Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test2 #236

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open

Test2 #236

Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8f29368
Use new PDFJS get Document syntax
gurpreet013 Mar 20, 2019
108d8bb
Merge pull request #1 from gurpreet013/pdf-preview-fix
gurpreet013 Mar 20, 2019
2f69434
Package json modified
gurpreet013 Mar 20, 2019
cefa614
Bump version to 1.1.1
gurpreet013 Mar 20, 2019
11c680d
Client Height Width Issue fixed for photoviewer
gurpreet013 Mar 21, 2019
76ae962
ios safari loadedmetadata event added for audio & video
gurpreet013 Mar 22, 2019
ea469d8
Display style property used instaed of visibility for audio & video
gurpreet013 Mar 29, 2019
d2ffcb5
Bump version to 1.1.4
gurpreet013 Mar 29, 2019
28ea961
Merge branch 'master' of github.com:plangrid/react-file-viewer
gurpreet013 Feb 18, 2020
0d0f2f3
Unique identifier used to render files to fix multiple file load on s…
gurpreet013 Jun 25, 2020
dea5b2b
Merge pull request #3 from gurpreet013/multiple_file_render_issues
gurpreet013 Jun 25, 2020
d7977be
1.1.5
gurpreet013 Jun 25, 2020
7069953
Only dist files to be inlcuded in npm package
gurpreet013 Oct 1, 2020
5b6c18e
PDF blur fix
manishrawat0212 Mar 30, 2021
27842ee
viewport: zoom calculation considered
manishrawat0212 Mar 30, 2021
b2c604a
Merge pull request #4 from gurpreet013/fix/pdf-blur
gurpreet013 Mar 31, 2021
a6750bc
Merge branch 'master' of github.com:gurpreet013/react-file-viewer
gurpreet013 Mar 31, 2021
171b253
version bumped to 2.0.2
gurpreet013 Mar 31, 2021
d198c68
Version bumped to 2.0.3
gurpreet013 Mar 31, 2021
539ec4c
package upgrades to fix high risk vulnerabilities
sergeyvelichkin Mar 17, 2022
bff4378
fix for failing test
sergeyvelichkin Mar 17, 2022
60eba30
was not compiling properly
sergeyvelichkin Mar 17, 2022
6cba8ce
Merge pull request #5 from sergeyvelichkin/package-upgrades-fix-vulne…
gurpreet013 Apr 12, 2023
6c7f7a7
Bump version to 2.1.0
gurpreet013 Apr 12, 2023
abbad8f
react-file-viewer
sylwesteropi Jun 29, 2023
2d5f537
tes
sylwesteropi Jun 29, 2023
d202c42
Merge remote-tracking branch 'origin/befor-push' into test2
sylwesteropi Jun 29, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@githubsylop:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=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
14,584 changes: 0 additions & 14,584 deletions package-lock.json

This file was deleted.

31 changes: 17 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"name": "react-file-viewer",
"version": "1.2.3",
"name": "react-file-viewer-extended",
"version": "2.2.0",
"description": "Extendable file viewer for web",
"main": "dist/index.js",
"module": "dist/index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/plangrid/react-file-viewer.git"
"url": "git+https://github.com/githubsylop/react-file-viewer-extend.git"
},
"scripts": {
"dev": "webpack -d --watch",
"build": "webpack -p --progress",
"start": "node ./scripts/start.js",
"lint": "node_modules/.bin/eslint ./src/**/*.jsx",
"test": "node_modules/.bin/jest --env=jsdom --watch",
"jest": "node_modules/.bin/jest --env=jsdom",
"lint": "node node_modules/.bin/eslint ./src/**/*.jsx",
"test": "node node_modules/.bin/jest --env=jsdom --watch",
"jest": "node node_modules/.bin/jest --env=jsdom",
"tag-and-publish": "node ./scripts/publish.js"
},
"author": "PlanGrid <opensource@plangrid.com>",
"author": "Gurpeet Singh <gurpreet013013@gmail.com>",
"contributors": [
{
"name": "Alexei Schiopu",
@@ -35,9 +35,9 @@
],
"license": "MIT",
"bugs": {
"url": "https://github.com/plangrid/react-file-viewer/issues"
"url": "https://github.com/gurpreet013/react-file-viewer/issues"
},
"homepage": "https://github.com/plangrid/react-file-viewer#readme",
"homepage": "https://github.com/gurpreet013/react-file-viewer#readme",
"devDependencies": {
"autoprefixer": "^7.1.0",
"babel-core": "^6.24.1",
@@ -66,7 +66,7 @@
"html-webpack-plugin": "^2.28.0",
"inquirer": "^3.0.6",
"jest": "^23.6.0",
"node-sass": "^4.5.3",
"node-sass": "^4.14.1",
"postcss-loader": "^2.0.5",
"react": "^16.6.3",
"react-dom": "^16.6.3",
@@ -79,18 +79,21 @@
},
"dependencies": {
"comma-separated-values": "^3.6.4",
"mammoth": "1.3.6",
"pdfjs-dist": "1.8.357",
"mammoth": "^1.4.21",
"pdfjs-dist": "^v2.6.347",
"prop-types": "^15.5.10",
"react-data-grid": "^5.0.5",
"react-visibility-sensor": "^5.0.2",
"three": "0.85.2",
"xlsx": "^0.10.1"
"three": "^0.138.3",
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.0/xlsx-0.20.0.tgz"
},
"peerDependencies": {
"react": "^16.6.3",
"react-dom": "^16.6.3"
},
"files": [
"dist/**/*"
],
"jest": {
"testPathIgnorePatterns": [
"<rootDir>[/\\\\](build|node_modules|scripts|example_files)[/\\\\]"
2 changes: 1 addition & 1 deletion scripts/start.js
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ process.on('unhandledRejection', err => {
throw err;
});

const PORT = 8081;
const PORT = 8082;

const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
16 changes: 14 additions & 2 deletions src/components/drivers/audio-viewer.jsx
Original file line number Diff line number Diff line change
@@ -11,6 +11,17 @@ class AudioViewer extends Component {
this.state = {
loading: true,
};
this.onCanPlay = this.onCanPlay.bind(this);
}

componentDidMount() {
if (this.audio) {
this.audio.addEventListener('loadedmetadata', this.onCanPlay);
}
}

componentWillUnmount() {
this.audio.removeEventListener('loadedmetadata', this.onCanPlay);
}

onCanPlay() {
@@ -25,14 +36,15 @@ class AudioViewer extends Component {
}

render() {
const visibility = this.state.loading ? 'hidden' : 'visible';
const display = this.state.loading ? 'none' : 'block';
return (
<div className="pg-driver-view">
<div className="video-container">
{this.renderLoading()}
<audio
style={{ visibility }}
style={{ display }}
controls
ref={audio => this.audio = audio}
onCanPlay={e => this.onCanPlay(e)}
src={this.props.filePath}
>
17 changes: 9 additions & 8 deletions src/components/drivers/docx-viewer.jsx
Original file line number Diff line number Diff line change
@@ -17,24 +17,25 @@ export default class extends Component {
mammoth.convertToHtml(
{ arrayBuffer: jsonFile.response },
{ includeDefaultStyleMap: true },
)
.then((result) => {
).then((result) => {
const docEl = document.createElement('div');
docEl.className = 'document-container';
docEl.innerHTML = result.value;
document.getElementById('docx').innerHTML = docEl.outerHTML;
})
.catch((a) => {
document.getElementById(this.getElementId()).innerHTML = docEl.outerHTML;
}).catch((a) => {
console.log('alexei: something went wrong', a);
})
.done();
}).done();
}
};
}

getElementId() {
return `docx-${this.props.uniqIdentifier}`;
}

render() {
return (
<div id="docx">
<div id={this.getElementId()}>
<Loading />
</div>);
}
17 changes: 8 additions & 9 deletions src/components/drivers/pdf-viewer.jsx
Original file line number Diff line number Diff line change
@@ -2,12 +2,11 @@

import React from 'react';
import VisibilitySensor from 'react-visibility-sensor';
import { PDFJS } from 'pdfjs-dist/build/pdf.combined';
import 'pdfjs-dist/web/compatibility';
import * as PDFJS from 'pdfjs-dist/legacy/build/pdf';

PDFJS.disableWorker = true;
const INCREASE_PERCENTAGE = 0.2;
const DEFAULT_SCALE = 1.1;
const DEFAULT_SCALE = 1;

export class PDFPage extends React.Component {
constructor(props) {
@@ -45,8 +44,7 @@ export class PDFPage extends React.Component {
renderPage(page) {
const { containerWidth, zoom } = this.props;
const calculatedScale = (containerWidth / page.getViewport(DEFAULT_SCALE).width);
const scale = calculatedScale > DEFAULT_SCALE ? DEFAULT_SCALE : calculatedScale;
const viewport = page.getViewport(scale + zoom);
const viewport = page.getViewport(calculatedScale + zoom);
const { width, height } = viewport;

const context = this.canvas.getContext('2d');
@@ -67,7 +65,7 @@ export class PDFPage extends React.Component {
<VisibilitySensor onChange={this.onChange} partialVisibility >
<canvas ref={node => this.canvas = node} width="670" height="870" />
</VisibilitySensor>
)
)
}
</div>
);
@@ -91,9 +89,10 @@ export default class PDFDriver extends React.Component {

componentDidMount() {
const { filePath } = this.props;
const containerWidth = this.container.offsetWidth;
PDFJS.getDocument(filePath, null, null, this.progressCallback.bind(this)).then((pdf) => {
this.setState({ pdf, containerWidth });
const loadingTask = PDFJS.getDocument(filePath);
loadingTask.onProgress = this.progressCallback.bind(this);
loadingTask.promise.then((pdf) => {
this.setState({ pdf, containerWidth: this.container ? this.container.offsetWidth : 0 });
});
}

8 changes: 6 additions & 2 deletions src/components/drivers/photo-viewer.jsx
Original file line number Diff line number Diff line change
@@ -12,7 +12,11 @@ export default class PhotoViewer extends Component {
this.props.texture.image.style.width = `${imageDimensions.width}px`;
this.props.texture.image.style.height = `${imageDimensions.height}px`;
this.props.texture.image.setAttribute('class', 'photo');
document.getElementById('pg-photo-container').appendChild(this.props.texture.image);
document.getElementById(this.getElementId()).appendChild(this.props.texture.image);
}

getElementId() {
return `pg-photo-container-${this.props.uniqIdentifier}`;
}

getImageDimensions(originalWidth, originalHeight) {
@@ -46,7 +50,7 @@ export default class PhotoViewer extends Component {
};

return (
<div style={containerStyles} className="photo-viewer-container" id="pg-photo-container" />
<div style={containerStyles} className="photo-viewer-container" id={this.getElementId()} />
);
}
}
7 changes: 5 additions & 2 deletions src/components/drivers/photo360-viewer.jsx
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ export default class extends Component {
}

componentDidMount() {
const el = document.getElementById('360-photo');
const el = document.getElementById(this.getElementId());
const positionInfo = el.getBoundingClientRect();
const height = positionInfo.height;
const width = positionInfo.width;
@@ -89,6 +89,9 @@ export default class extends Component {
});
}

getElementId() {
return `360-photo-${this.props.uniqIdentifier}`;
}

updateView() {
const latitude = Math.max(-85, Math.min(85, this.state.latitude));
@@ -106,7 +109,7 @@ export default class extends Component {
render() {
return (
<div
id="360-photo"
id={this.getElementId()}
className="photo360"
onMouseDown={this.onMouseDown}
onMouseMove={this.onMouseMove}
14 changes: 12 additions & 2 deletions src/components/drivers/video-viewer.jsx
Original file line number Diff line number Diff line change
@@ -11,6 +11,15 @@ class VideoViewer extends Component {
this.state = {
loading: true,
};
this.onCanPlay = this.onCanPlay.bind(this);
}

componentDidMount() {
this.video.addEventListener('loadedmetadata', this.onCanPlay);
}

componentWillUnmount() {
this.video.removeEventListener('loadedmetadata', this.onCanPlay);
}

onCanPlay() {
@@ -25,16 +34,17 @@ class VideoViewer extends Component {
}

render() {
const visibility = this.state.loading ? 'hidden' : 'visible';
const display = this.state.loading ? 'none' : 'block';
return (
<div className="pg-driver-view">
<div className="video-container">
{this.renderLoading()}
<video
style={{ visibility }}
style={{ display }}
controls
type={`video/${this.props.fileType}`}
onCanPlay={e => this.onCanPlay(e)}
ref={video => this.video = video}
src={this.props.filePath}
>
Video playback is not supported by your browser.
22 changes: 10 additions & 12 deletions src/components/file-viewer.jsx
Original file line number Diff line number Diff line change
@@ -20,25 +20,19 @@ import {
class FileViewer extends Component {
constructor(props) {
super(props);
this.uniqIdentifier = Math.floor(Math.random() * 100000);
this.state = {
loading: true,
};
}

componentDidMount() {
const container = document.getElementById('pg-viewer');
const height = container ? container.clientHeight : 0;
const width = container ? container.clientWidth : 0;
this.setState({ height, width });
}

getDriver() {
getDriver(commonProps) {
switch (this.props.fileType) {
case 'csv': {
return withFetching(CsvViewer, this.props);
return withFetching(CsvViewer, commonProps);
}
case 'xlsx': {
const newProps = Object.assign({}, this.props, { responseType: 'arraybuffer' });
const newProps = Object.assign({}, commonProps, { responseType: 'arraybuffer' });
return withFetching(XlsxViewer, newProps);
}
case 'jpg':
@@ -71,11 +65,15 @@ class FileViewer extends Component {
}

render() {
const Driver = this.getDriver(this.props);
const commonProps = Object.assign({}, this.props, { uniqIdentifier: this.uniqIdentifier });
const Driver = this.getDriver(commonProps);
const container = document.getElementById('pg-viewer');
const height = container ? container.clientHeight : 0;
const width = container ? container.clientWidth : 0;
return (
<div className="pg-viewer-wrapper">
<div className="pg-viewer" id="pg-viewer">
<Driver {...this.props} width={this.state.width} height={this.state.height} />
<Driver {...commonProps} width={width} height={height} />
</div>
</div>
);
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ exports[`AudioViewer matches snapshot 1`] = `
src="fake/path"
style={
Object {
"visibility": "hidden",
"display": "none",
}
}
>
6 changes: 0 additions & 6 deletions webpack.config.dev.js
Original file line number Diff line number Diff line change
@@ -66,12 +66,6 @@ module.exports = {
},
],
},
{
test: /\.(js|jsx)$/,
loader: 'eslint-loader',
include: path.resolve(__dirname, 'src'),
enforce: 'pre',
},
{
test: [/\.wexbim$/, /\.jpg$/, /\.docx$/, /\.csv$/, /\.mp4$/, /\.xlsx$/, /\.doc$/, /\.avi$/, /\.webm$/, /\.mov$/, /\.mp3$/, /\.rtf$/, /\.pdf$/],
loader: 'file-loader',