@flyfish-group/file-viewer-react 1.0.25 → 2.0.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/LICENSE +160 -0
- package/README.en.md +39 -0
- package/README.md +6 -17
- package/dist/index.d.ts +2 -54
- package/dist/index.js +1 -112
- package/package.json +12 -11
package/LICENSE
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction, and
|
|
10
|
+
distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright
|
|
13
|
+
owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities
|
|
16
|
+
that control, are controlled by, or are under common control with that entity.
|
|
17
|
+
For the purposes of this definition, "control" means (i) the power, direct or
|
|
18
|
+
indirect, to cause the direction or management of such entity, whether by
|
|
19
|
+
contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
20
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
21
|
+
|
|
22
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
|
23
|
+
permissions granted by this License.
|
|
24
|
+
|
|
25
|
+
"Source" form shall mean the preferred form for making modifications, including
|
|
26
|
+
but not limited to software source code, documentation source, and configuration
|
|
27
|
+
files.
|
|
28
|
+
|
|
29
|
+
"Object" form shall mean any form resulting from mechanical transformation or
|
|
30
|
+
translation of a Source form, including but not limited to compiled object code,
|
|
31
|
+
generated documentation, and conversions to other media types.
|
|
32
|
+
|
|
33
|
+
"Work" shall mean the work of authorship, whether in Source or Object form,
|
|
34
|
+
made available under the License, as indicated by a copyright notice that is
|
|
35
|
+
included in or attached to the work.
|
|
36
|
+
|
|
37
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that
|
|
38
|
+
is based on (or derived from) the Work and for which the editorial revisions,
|
|
39
|
+
annotations, elaborations, or other modifications represent, as a whole, an
|
|
40
|
+
original work of authorship. For the purposes of this License, Derivative Works
|
|
41
|
+
shall not include works that remain separable from, or merely link (or bind by
|
|
42
|
+
name) to the interfaces of, the Work and Derivative Works thereof.
|
|
43
|
+
|
|
44
|
+
"Contribution" shall mean any work of authorship, including the original version
|
|
45
|
+
of the Work and any modifications or additions to that Work or Derivative Works
|
|
46
|
+
thereof, that is intentionally submitted to Licensor for inclusion in the Work by
|
|
47
|
+
the copyright owner or by an individual or Legal Entity authorized to submit on
|
|
48
|
+
behalf of the copyright owner. For the purposes of this definition, "submitted"
|
|
49
|
+
means any form of electronic, verbal, or written communication sent to the
|
|
50
|
+
Licensor or its representatives, including but not limited to communication on
|
|
51
|
+
electronic mailing lists, source code control systems, and issue tracking systems
|
|
52
|
+
that are managed by, or on behalf of, the Licensor for the purpose of discussing
|
|
53
|
+
and improving the Work, but excluding communication that is conspicuously marked
|
|
54
|
+
or otherwise designated in writing by the copyright owner as "Not a
|
|
55
|
+
Contribution."
|
|
56
|
+
|
|
57
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
|
|
58
|
+
of whom a Contribution has been received by Licensor and subsequently
|
|
59
|
+
incorporated within the Work.
|
|
60
|
+
|
|
61
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this
|
|
62
|
+
License, each Contributor hereby grants to You a perpetual, worldwide,
|
|
63
|
+
non-exclusive, no-charge, royalty-free, irrevocable copyright license to
|
|
64
|
+
reproduce, prepare Derivative Works of, publicly display, publicly perform,
|
|
65
|
+
sublicense, and distribute the Work and such Derivative Works in Source or
|
|
66
|
+
Object form.
|
|
67
|
+
|
|
68
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License,
|
|
69
|
+
each Contributor hereby grants to You a perpetual, worldwide, non-exclusive,
|
|
70
|
+
no-charge, royalty-free, irrevocable (except as stated in this section) patent
|
|
71
|
+
license to make, have made, use, offer to sell, sell, import, and otherwise
|
|
72
|
+
transfer the Work, where such license applies only to those patent claims
|
|
73
|
+
licensable by such Contributor that are necessarily infringed by their
|
|
74
|
+
Contribution(s) alone or by combination of their Contribution(s) with the Work to
|
|
75
|
+
which such Contribution(s) was submitted. If You institute patent litigation
|
|
76
|
+
against any entity (including a cross-claim or counterclaim in a lawsuit)
|
|
77
|
+
alleging that the Work or a Contribution incorporated within the Work
|
|
78
|
+
constitutes direct or contributory patent infringement, then any patent licenses
|
|
79
|
+
granted to You under this License for that Work shall terminate as of the date
|
|
80
|
+
such litigation is filed.
|
|
81
|
+
|
|
82
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or
|
|
83
|
+
Derivative Works thereof in any medium, with or without modifications, and in
|
|
84
|
+
Source or Object form, provided that You meet the following conditions:
|
|
85
|
+
|
|
86
|
+
(a) You must give any other recipients of the Work or Derivative Works a copy of
|
|
87
|
+
this License; and
|
|
88
|
+
|
|
89
|
+
(b) You must cause any modified files to carry prominent notices stating that
|
|
90
|
+
You changed the files; and
|
|
91
|
+
|
|
92
|
+
(c) You must retain, in the Source form of any Derivative Works that You
|
|
93
|
+
distribute, all copyright, patent, trademark, and attribution notices from the
|
|
94
|
+
Source form of the Work, excluding those notices that do not pertain to any part
|
|
95
|
+
of the Derivative Works; and
|
|
96
|
+
|
|
97
|
+
(d) If the Work includes a "NOTICE" text file as part of its distribution, then
|
|
98
|
+
any Derivative Works that You distribute must include a readable copy of the
|
|
99
|
+
attribution notices contained within such NOTICE file, excluding those notices
|
|
100
|
+
that do not pertain to any part of the Derivative Works, in at least one of the
|
|
101
|
+
following places: within a NOTICE text file distributed as part of the Derivative
|
|
102
|
+
Works; within the Source form or documentation, if provided along with the
|
|
103
|
+
Derivative Works; or, within a display generated by the Derivative Works, if and
|
|
104
|
+
wherever such third-party notices normally appear. The contents of the NOTICE
|
|
105
|
+
file are for informational purposes only and do not modify the License. You may
|
|
106
|
+
add Your own attribution notices within Derivative Works that You distribute,
|
|
107
|
+
alongside or as an addendum to the NOTICE text from the Work, provided that such
|
|
108
|
+
additional attribution notices cannot be construed as modifying the License.
|
|
109
|
+
|
|
110
|
+
You may add Your own copyright statement to Your modifications and may provide
|
|
111
|
+
additional or different license terms and conditions for use, reproduction, or
|
|
112
|
+
distribution of Your modifications, or for any such Derivative Works as a whole,
|
|
113
|
+
provided Your use, reproduction, and distribution of the Work otherwise complies
|
|
114
|
+
with the conditions stated in this License.
|
|
115
|
+
|
|
116
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any
|
|
117
|
+
Contribution intentionally submitted for inclusion in the Work by You to the
|
|
118
|
+
Licensor shall be under the terms and conditions of this License, without any
|
|
119
|
+
additional terms or conditions. Notwithstanding the above, nothing herein shall
|
|
120
|
+
supersede or modify the terms of any separate license agreement you may have
|
|
121
|
+
executed with Licensor regarding such Contributions.
|
|
122
|
+
|
|
123
|
+
6. Trademarks. This License does not grant permission to use the trade names,
|
|
124
|
+
trademarks, service marks, or product names of the Licensor, except as required
|
|
125
|
+
for reasonable and customary use in describing the origin of the Work and
|
|
126
|
+
reproducing the content of the NOTICE file.
|
|
127
|
+
|
|
128
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
|
|
129
|
+
writing, Licensor provides the Work (and each Contributor provides its
|
|
130
|
+
Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
131
|
+
KIND, either express or implied, including, without limitation, any warranties or
|
|
132
|
+
conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
133
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
134
|
+
appropriateness of using or redistributing the Work and assume any risks
|
|
135
|
+
associated with Your exercise of permissions under this License.
|
|
136
|
+
|
|
137
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in
|
|
138
|
+
tort (including negligence), contract, or otherwise, unless required by
|
|
139
|
+
applicable law (such as deliberate and grossly negligent acts) or agreed to in
|
|
140
|
+
writing, shall any Contributor be liable to You for damages, including any
|
|
141
|
+
direct, indirect, special, incidental, or consequential damages of any character
|
|
142
|
+
arising as a result of this License or out of the use or inability to use the
|
|
143
|
+
Work (including but not limited to damages for loss of goodwill, work stoppage,
|
|
144
|
+
computer failure or malfunction, or any and all other commercial damages or
|
|
145
|
+
losses), even if such Contributor has been advised of the possibility of such
|
|
146
|
+
damages.
|
|
147
|
+
|
|
148
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or
|
|
149
|
+
Derivative Works thereof, You may choose to offer, and charge a fee for,
|
|
150
|
+
acceptance of support, warranty, indemnity, or other liability obligations and/or
|
|
151
|
+
rights consistent with this License. However, in accepting such obligations, You
|
|
152
|
+
may act only on Your own behalf and on Your sole responsibility, not on behalf of
|
|
153
|
+
any other Contributor, and only if You agree to indemnify, defend, and hold each
|
|
154
|
+
Contributor harmless for any liability incurred by, or claims asserted against,
|
|
155
|
+
such Contributor by reason of your accepting any such warranty or additional
|
|
156
|
+
liability.
|
|
157
|
+
|
|
158
|
+
END OF TERMS AND CONDITIONS
|
|
159
|
+
|
|
160
|
+
Copyright 2026 Flyfish Viewer
|
package/README.en.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# @flyfish-group/file-viewer-react
|
|
2
|
+
|
|
3
|
+
React file preview component. This package is the historical alias of `@file-viewer/react` and now provides the same native React component experience: it mounts the shared core directly and exposes consistent props, events, and ref APIs.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @flyfish-group/file-viewer-react
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
import FileViewer from '@flyfish-group/file-viewer-react'
|
|
11
|
+
|
|
12
|
+
export function Preview() {
|
|
13
|
+
return (
|
|
14
|
+
<div style={{ height: '100vh' }}>
|
|
15
|
+
<FileViewer
|
|
16
|
+
url="/files/demo.docx"
|
|
17
|
+
options={{
|
|
18
|
+
theme: 'light',
|
|
19
|
+
toolbar: { position: 'bottom-right' },
|
|
20
|
+
archive: { cache: true }
|
|
21
|
+
}}
|
|
22
|
+
onViewerEvent={(event) => {
|
|
23
|
+
console.log(event.type, event.event, event.payload)
|
|
24
|
+
}}
|
|
25
|
+
/>
|
|
26
|
+
</div>
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
`file` takes precedence over `url`. When passing a `Blob` or `ArrayBuffer`, also provide `name`, for example `contract.pdf`, so the viewer can detect the format:
|
|
32
|
+
|
|
33
|
+
```tsx
|
|
34
|
+
<FileViewer file={blob} name="contract.pdf" />
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
`options` cover theme, watermarking, search, unified zoom, download, print, HTML export, beforeOperation guards, lifecycle hooks, and format-specific settings. Lifecycle, operation availability, search state, and document location updates are emitted through `onViewerEvent`.
|
|
38
|
+
|
|
39
|
+
New projects should prefer the standard package name `@file-viewer/react`. Official documentation: https://doc.flyfish-viewer.app/
|
package/README.md
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
# @flyfish-group/file-viewer-react
|
|
2
2
|
|
|
3
|
-
React
|
|
3
|
+
React 文件预览组件。这个包是 `@file-viewer/react` 的历史包名同步版本,当前提供原生 React 组件体验: 组件内部直接挂载共享预览底座,并暴露一致的 props、事件和 ref API。
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
|
-
npm install @flyfish-group/file-viewer-react
|
|
6
|
+
npm install @flyfish-group/file-viewer-react
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
-
pnpm 10 默认会拦截依赖包的 `postinstall`。如果安装后提示 `Ignored build scripts: @flyfish-group/file-viewer-web`,请执行 `pnpm approve-builds` 允许该包,或运行 `pnpm exec file-viewer-copy-assets ./public/file-viewer`。复制脚本会先清空目标目录再复制,避免 `index.html` 和 `assets/*` hash 不同版本导致动态 import 404。
|
|
10
|
-
|
|
11
9
|
```tsx
|
|
12
10
|
import FileViewer from '@flyfish-group/file-viewer-react'
|
|
13
11
|
|
|
@@ -23,10 +21,7 @@ export function Preview() {
|
|
|
23
21
|
theme: 'light',
|
|
24
22
|
toolbar: { position: 'bottom-right' },
|
|
25
23
|
watermark: { text: '内部预览', opacity: 0.14 },
|
|
26
|
-
archive: {
|
|
27
|
-
workerUrl: '/file-viewer/vendor/libarchive/worker-bundle.js',
|
|
28
|
-
cache: true
|
|
29
|
-
}
|
|
24
|
+
archive: { cache: true }
|
|
30
25
|
}}
|
|
31
26
|
/>
|
|
32
27
|
</div>
|
|
@@ -34,18 +29,12 @@ export function Preview() {
|
|
|
34
29
|
}
|
|
35
30
|
```
|
|
36
31
|
|
|
37
|
-
`file` 优先级高于 `url`。当传入 `Blob` 或 `ArrayBuffer` 时,请同时传 `name`,例如 `contract.pdf
|
|
32
|
+
`file` 优先级高于 `url`。当传入 `Blob` 或 `ArrayBuffer` 时,请同时传 `name`,例如 `contract.pdf`,用于识别格式:
|
|
38
33
|
|
|
39
34
|
```tsx
|
|
40
35
|
<FileViewer file={blob} name="contract.pdf" />
|
|
41
36
|
```
|
|
42
37
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
```tsx
|
|
46
|
-
<FileViewer viewerUrl="/vendor/file-viewer/index.html" url={url} />
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
React 组件内部复用 `mountViewerFrame` 的地址协议,会默认追加 `__flyfish_viewer_version` 来绕开旧 iframe 入口页缓存;静态服务已经保证 HTML 不缓存时,可传 `cacheKey={false}` 关闭。
|
|
38
|
+
`options` 支持主题、水印、搜索、统一缩放、下载、打印、导出 HTML、beforeOperation 前置校验、生命周期 hooks 和格式专项参数。生命周期、操作能力变化、搜索状态和当前位置会通过 `onViewerEvent` 回传给宿主。
|
|
50
39
|
|
|
51
|
-
|
|
40
|
+
新项目建议优先使用标准包名 `@file-viewer/react`。官方文档: https://doc.flyfish-viewer.app/
|
package/dist/index.d.ts
CHANGED
|
@@ -1,54 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export type { FileRef, ViewerFrameEventHandler, ViewerFrameOptions, ViewerRuntimeOptions, ViewerToolbarOptions, ViewerToolbarPosition, ViewerThemeMode } from '@flyfish-group/file-viewer-web';
|
|
4
|
-
export interface FileViewerHandle {
|
|
5
|
-
iframe: HTMLIFrameElement | null;
|
|
6
|
-
postFile(): boolean;
|
|
7
|
-
reload(): void;
|
|
8
|
-
}
|
|
9
|
-
export interface FileViewerProps extends Omit<IframeHTMLAttributes<HTMLIFrameElement>, 'children' | 'src'> {
|
|
10
|
-
/**
|
|
11
|
-
* 私有化部署后的 Vue 基线预览器页面地址。
|
|
12
|
-
*
|
|
13
|
-
* 不传时默认使用 `@flyfish-group/file-viewer-web` 安装后复制到宿主项目的 `/file-viewer/index.html`。
|
|
14
|
-
*/
|
|
15
|
-
viewerUrl?: string;
|
|
16
|
-
/**
|
|
17
|
-
* 远端文件地址。会透传给 iframe 里的 Vue 基线预览器。
|
|
18
|
-
*/
|
|
19
|
-
url?: string;
|
|
20
|
-
/**
|
|
21
|
-
* 本地二进制输入。优先级高于 url,会通过 postMessage 推送给 iframe。
|
|
22
|
-
*/
|
|
23
|
-
file?: FileRef;
|
|
24
|
-
/**
|
|
25
|
-
* 当 file 是 Blob 或 ArrayBuffer 时用于识别扩展名。
|
|
26
|
-
*/
|
|
27
|
-
name?: string;
|
|
28
|
-
/**
|
|
29
|
-
* 允许推送二进制的宿主 origin。默认取当前页面 origin。
|
|
30
|
-
*/
|
|
31
|
-
from?: string;
|
|
32
|
-
/**
|
|
33
|
-
* postMessage 的目标 origin。默认从 viewerUrl 推导。
|
|
34
|
-
*/
|
|
35
|
-
targetOrigin?: string;
|
|
36
|
-
/**
|
|
37
|
-
* 预留给 Vue 基线页面的查询参数。
|
|
38
|
-
*/
|
|
39
|
-
params?: ViewerFrameOptions['params'];
|
|
40
|
-
/**
|
|
41
|
-
* iframe 入口页的缓存标识。默认使用 web 包版本;传 false 可关闭。
|
|
42
|
-
*/
|
|
43
|
-
cacheKey?: ViewerFrameOptions['cacheKey'];
|
|
44
|
-
/**
|
|
45
|
-
* 透传给 Vue 基线预览器的运行时选项,例如水印、工具栏和压缩包缓存限制。
|
|
46
|
-
*/
|
|
47
|
-
options?: ViewerFrameOptions['options'];
|
|
48
|
-
/**
|
|
49
|
-
* iframe 模式下接收基线预览器抛出的生命周期和操作事件。
|
|
50
|
-
*/
|
|
51
|
-
onViewerEvent?: ViewerFrameEventHandler;
|
|
52
|
-
}
|
|
53
|
-
export declare const FileViewer: import("react").ForwardRefExoticComponent<FileViewerProps & import("react").RefAttributes<FileViewerHandle>>;
|
|
54
|
-
export default FileViewer;
|
|
1
|
+
export { FileViewer, default, } from '@file-viewer/react';
|
|
2
|
+
export type { FileRef, FileViewerHandle, FileViewerProps, ViewerAiOptions, ViewerArchiveOptions, ViewerCadOptions, ViewerController, ViewerControllerAccessor, ViewerControllerHandle, ViewerDocxOptions, ViewerEvent, ViewerEventHandler, ViewerEventType, ViewerMountOptions, ViewerOptions, ViewerPdfOptions, ViewerSpreadsheetOptions, ViewerSearchOptions, ViewerThemeMode, ViewerToolbarOptions, ViewerToolbarPosition, ViewerTypstOptions, ViewerWatermarkOptions, } from '@file-viewer/react';
|
package/dist/index.js
CHANGED
|
@@ -1,112 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
3
|
-
import { buildViewerSrc, postFileToViewer } from '@flyfish-group/file-viewer-web';
|
|
4
|
-
const defaultStyle = {
|
|
5
|
-
width: '100%',
|
|
6
|
-
height: '100%',
|
|
7
|
-
border: 0,
|
|
8
|
-
display: 'block'
|
|
9
|
-
};
|
|
10
|
-
export const FileViewer = forwardRef((props, forwardedRef) => {
|
|
11
|
-
const { viewerUrl, url, file, name, from, targetOrigin, params, cacheKey, options, onViewerEvent, onLoad, style, title = 'Flyfish Viewer 文件预览', ...iframeProps } = props;
|
|
12
|
-
const iframeRef = useRef(null);
|
|
13
|
-
const [frameReady, setFrameReady] = useState(false);
|
|
14
|
-
const frameOptions = useMemo(() => ({
|
|
15
|
-
viewerUrl,
|
|
16
|
-
url,
|
|
17
|
-
file,
|
|
18
|
-
name,
|
|
19
|
-
from,
|
|
20
|
-
targetOrigin,
|
|
21
|
-
params,
|
|
22
|
-
cacheKey,
|
|
23
|
-
options
|
|
24
|
-
}), [viewerUrl, url, file, name, from, targetOrigin, params, cacheKey, options]);
|
|
25
|
-
const src = useMemo(() => buildViewerSrc(frameOptions), [frameOptions]);
|
|
26
|
-
const retryTimerRef = useRef(undefined);
|
|
27
|
-
const retryCountRef = useRef(0);
|
|
28
|
-
const lifecycleAcknowledgedRef = useRef(false);
|
|
29
|
-
const postFile = useCallback(() => {
|
|
30
|
-
return postFileToViewer(iframeRef.current, frameOptions);
|
|
31
|
-
}, [frameOptions]);
|
|
32
|
-
const clearFilePostRetry = useCallback(() => {
|
|
33
|
-
if (retryTimerRef.current) {
|
|
34
|
-
window.clearTimeout(retryTimerRef.current);
|
|
35
|
-
retryTimerRef.current = undefined;
|
|
36
|
-
}
|
|
37
|
-
}, []);
|
|
38
|
-
const scheduleFilePost = useCallback(() => {
|
|
39
|
-
clearFilePostRetry();
|
|
40
|
-
retryCountRef.current = 0;
|
|
41
|
-
lifecycleAcknowledgedRef.current = false;
|
|
42
|
-
if (!frameOptions.file) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
const post = () => {
|
|
46
|
-
if (lifecycleAcknowledgedRef.current) {
|
|
47
|
-
clearFilePostRetry();
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
postFile();
|
|
51
|
-
retryCountRef.current += 1;
|
|
52
|
-
if (retryCountRef.current < 8) {
|
|
53
|
-
retryTimerRef.current = window.setTimeout(post, 120);
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
retryTimerRef.current = undefined;
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
post();
|
|
60
|
-
}, [clearFilePostRetry, frameOptions.file, postFile]);
|
|
61
|
-
const reload = useCallback(() => {
|
|
62
|
-
if (iframeRef.current) {
|
|
63
|
-
iframeRef.current.src = src;
|
|
64
|
-
}
|
|
65
|
-
}, [src]);
|
|
66
|
-
useImperativeHandle(forwardedRef, () => ({
|
|
67
|
-
get iframe() {
|
|
68
|
-
return iframeRef.current;
|
|
69
|
-
},
|
|
70
|
-
postFile,
|
|
71
|
-
reload
|
|
72
|
-
}), [postFile, reload]);
|
|
73
|
-
useEffect(() => {
|
|
74
|
-
clearFilePostRetry();
|
|
75
|
-
lifecycleAcknowledgedRef.current = false;
|
|
76
|
-
setFrameReady(false);
|
|
77
|
-
}, [clearFilePostRetry, src]);
|
|
78
|
-
useEffect(() => {
|
|
79
|
-
if (frameReady) {
|
|
80
|
-
scheduleFilePost();
|
|
81
|
-
}
|
|
82
|
-
}, [frameReady, scheduleFilePost]);
|
|
83
|
-
useEffect(() => {
|
|
84
|
-
const handleMessage = (event) => {
|
|
85
|
-
var _a, _b, _c;
|
|
86
|
-
if (event.source !== ((_a = iframeRef.current) === null || _a === void 0 ? void 0 : _a.contentWindow)) {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
if (((_b = event.data) === null || _b === void 0 ? void 0 : _b.type) !== 'flyfish-viewer:lifecycle' &&
|
|
90
|
-
((_c = event.data) === null || _c === void 0 ? void 0 : _c.type) !== 'flyfish-viewer:operation') {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
if (event.data.type === 'flyfish-viewer:lifecycle') {
|
|
94
|
-
lifecycleAcknowledgedRef.current = true;
|
|
95
|
-
clearFilePostRetry();
|
|
96
|
-
}
|
|
97
|
-
onViewerEvent === null || onViewerEvent === void 0 ? void 0 : onViewerEvent(event.data, event);
|
|
98
|
-
};
|
|
99
|
-
window.addEventListener('message', handleMessage);
|
|
100
|
-
return () => window.removeEventListener('message', handleMessage);
|
|
101
|
-
}, [clearFilePostRetry, onViewerEvent]);
|
|
102
|
-
useEffect(() => {
|
|
103
|
-
return () => clearFilePostRetry();
|
|
104
|
-
}, [clearFilePostRetry]);
|
|
105
|
-
const handleLoad = useCallback((event) => {
|
|
106
|
-
setFrameReady(true);
|
|
107
|
-
onLoad === null || onLoad === void 0 ? void 0 : onLoad(event);
|
|
108
|
-
}, [onLoad]);
|
|
109
|
-
return (_jsx("iframe", { ...iframeProps, ref: iframeRef, src: src, title: title, style: { ...defaultStyle, ...style }, onLoad: handleLoad }));
|
|
110
|
-
});
|
|
111
|
-
FileViewer.displayName = 'FileViewer';
|
|
112
|
-
export default FileViewer;
|
|
1
|
+
export { FileViewer, default, } from '@file-viewer/react';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flyfish-group/file-viewer-react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Private-deploy React component for Flyfish Viewer",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"file-viewer",
|
|
9
9
|
"document-preview",
|
|
10
10
|
"react",
|
|
11
|
-
"
|
|
11
|
+
"native-viewer",
|
|
12
12
|
"office-preview"
|
|
13
13
|
],
|
|
14
14
|
"publishConfig": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"repository": {
|
|
23
23
|
"type": "git",
|
|
24
24
|
"url": "git+https://github.com/flyfish-dev/file-viewer.git",
|
|
25
|
-
"directory": "packages/react"
|
|
25
|
+
"directory": "packages/compat/react"
|
|
26
26
|
},
|
|
27
27
|
"homepage": "https://github.com/flyfish-dev/file-viewer",
|
|
28
28
|
"bugs": {
|
|
@@ -41,22 +41,23 @@
|
|
|
41
41
|
},
|
|
42
42
|
"files": [
|
|
43
43
|
"dist",
|
|
44
|
-
"README.md"
|
|
44
|
+
"README.md",
|
|
45
|
+
"README.en.md"
|
|
45
46
|
],
|
|
46
|
-
"scripts": {
|
|
47
|
-
"build": "tsc -b tsconfig.json",
|
|
48
|
-
"type-check": "tsc -b tsconfig.json"
|
|
49
|
-
},
|
|
50
47
|
"peerDependencies": {
|
|
51
48
|
"react": ">=17 <20"
|
|
52
49
|
},
|
|
53
50
|
"dependencies": {
|
|
54
|
-
"@
|
|
51
|
+
"@file-viewer/react": "^2.0.0"
|
|
55
52
|
},
|
|
56
53
|
"devDependencies": {
|
|
57
54
|
"@types/react": "^19.2.17",
|
|
58
55
|
"react": "^19.2.7",
|
|
59
56
|
"typescript": "^6.0.3"
|
|
60
57
|
},
|
|
61
|
-
"license": "Apache-2.0"
|
|
62
|
-
|
|
58
|
+
"license": "Apache-2.0",
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "tsc -b tsconfig.json",
|
|
61
|
+
"type-check": "tsc -b tsconfig.json"
|
|
62
|
+
}
|
|
63
|
+
}
|