ywana-core8 0.0.751 → 0.0.753
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/index.cjs +185 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +22 -19
- package/dist/index.css.map +1 -1
- package/dist/index.modern.js +185 -26
- package/dist/index.modern.js.map +1 -1
- package/dist/index.umd.js +185 -25
- package/dist/index.umd.js.map +1 -1
- package/package.json +3 -1
- package/src/domain/CollectionPage.js +1 -0
- package/src/domain2/CollectionList.js +0 -2
- package/src/html/icon.js +17 -2
- package/src/html/list.js +2 -2
- package/src/incubator/pdfViewer.js +31 -0
- package/src/widgets/image/ImageViewer.css +3 -0
- package/src/widgets/image/ImageViewer.js +140 -0
- package/src/widgets/index.js +2 -1
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "ywana-core8",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.753",
|
4
4
|
"description": "ywana-core8",
|
5
5
|
"homepage": "https://ywana.github.io/workspace",
|
6
6
|
"author": "Ernesto Roldan Garcia",
|
@@ -37,7 +37,9 @@
|
|
37
37
|
"moment-range": "^4.0.2",
|
38
38
|
"react-datepicker": "^4.6.0",
|
39
39
|
"react-error-overlay": "^6.0.10",
|
40
|
+
"react-image-pan-zoom-rotate": "^1.6.0",
|
40
41
|
"react-notifications-component": "^3.4.1",
|
42
|
+
"react-pdf": "^6.0.3",
|
41
43
|
"react-switch": "^6.0.0",
|
42
44
|
"react-tooltip": "^4.2.21",
|
43
45
|
"resumablejs": "^1.1.0"
|
package/src/html/icon.js
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
import React from 'react'
|
2
2
|
import './icon.css'
|
3
|
+
import { Tooltip } from './tooltip';
|
3
4
|
|
4
5
|
/**
|
5
6
|
* Icon
|
6
7
|
*/
|
7
|
-
export const Icon = ({ icon, size = "normal", clickable = false, disabled = false, action, eventPropagation = false, className }) => {
|
8
|
+
export const Icon = ({ icon, size = "normal", tooltip, clickable = false, disabled = false, action, eventPropagation = false, className }) => {
|
8
9
|
|
9
10
|
function click (event) {
|
10
11
|
if (!eventPropagation) {
|
@@ -15,9 +16,23 @@ export const Icon = ({ icon, size = "normal", clickable = false, disabled = fals
|
|
15
16
|
}
|
16
17
|
|
17
18
|
const style = disabled ? "disabled" : clickable ? "clickable" : ""
|
18
|
-
return (
|
19
|
+
return tooltip ? (
|
20
|
+
<Tooltip {...tooltip}>
|
21
|
+
<i className={`icon ${size} ${style} ${className} material-icons`} onClick={click} >
|
22
|
+
{icon}
|
23
|
+
</i>
|
24
|
+
</Tooltip>
|
25
|
+
) : (
|
19
26
|
<i className={`icon ${size} ${style} ${className} material-icons`} onClick={click}>
|
20
27
|
{icon}
|
21
28
|
</i>
|
22
29
|
)
|
30
|
+
}
|
31
|
+
|
32
|
+
const IconTest = (props) => {
|
33
|
+
return (
|
34
|
+
<div>
|
35
|
+
<Icon icon="add" tooltip={{ text: 'add', top: '2rem', left: '2rem'}}/>
|
36
|
+
</div>
|
37
|
+
)
|
23
38
|
}
|
package/src/html/list.js
CHANGED
@@ -62,7 +62,7 @@ const GroupedList = (props) => {
|
|
62
62
|
* List Item
|
63
63
|
*/
|
64
64
|
const ListItem = ({ item, selected, onSelect }) => {
|
65
|
-
const { id, icon, line1, line2, meta } = item
|
65
|
+
const { id, icon, iconTooltip, line1, line2, meta } = item
|
66
66
|
|
67
67
|
function select() {
|
68
68
|
if (onSelect) onSelect(id)
|
@@ -72,7 +72,7 @@ const ListItem = ({ item, selected, onSelect }) => {
|
|
72
72
|
const style = isSelected ? "selected" : ""
|
73
73
|
return (
|
74
74
|
<li className={`${style}`} onClick={select}>
|
75
|
-
{icon ? <Icon icon={icon} size="small" /> : null}
|
75
|
+
{icon ? <Icon icon={icon} size="small" tooltip={iconTooltip} /> : null}
|
76
76
|
<main>
|
77
77
|
<div className="primary-line"><Text>{line1}</Text></div>
|
78
78
|
{line2 ? <div className="secondary-line"><Text>{line2}</Text></div> : null}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import React from 'react'
|
2
|
+
import { Document, Page } from 'react-pdf/dist/esm/entry.webpack'
|
3
|
+
|
4
|
+
export const PDFViewer = (props) => {
|
5
|
+
|
6
|
+
const { file } = props
|
7
|
+
const [numPages, setNumPages] = useState(null)
|
8
|
+
const [pageNumber, setPageNumber] = useState(1)
|
9
|
+
|
10
|
+
function onDocumentLoadSuccess({ numPages }) {
|
11
|
+
setNumPages(numPages)
|
12
|
+
}
|
13
|
+
|
14
|
+
return (
|
15
|
+
<div className="pdfViewer">
|
16
|
+
<Document file={file} onLoadSuccess={onDocumentLoadSuccess}>
|
17
|
+
<Page pageNumber={pageNumber} />
|
18
|
+
</Document>
|
19
|
+
</div>
|
20
|
+
)
|
21
|
+
}
|
22
|
+
|
23
|
+
export const PDFViewerTest = (props) => {
|
24
|
+
|
25
|
+
const base64 = "xx"
|
26
|
+
|
27
|
+
return (
|
28
|
+
<PDFViewer file={base64} />
|
29
|
+
)
|
30
|
+
|
31
|
+
}
|
@@ -0,0 +1,140 @@
|
|
1
|
+
import React, { useRef, useMemo, useEffect, useState } from "react";
|
2
|
+
import './ImageViewer.css'
|
3
|
+
|
4
|
+
const ImageViewerTest = (props) => {
|
5
|
+
|
6
|
+
return (
|
7
|
+
<div>
|
8
|
+
<h1>ImageViewerTest</h1>
|
9
|
+
<ImageViewer image={"https://concepto.de/wp-content/uploads/2015/03/paisaje-800x409.jpg"} />
|
10
|
+
</div>
|
11
|
+
)
|
12
|
+
}
|
13
|
+
|
14
|
+
const SCROLL_SENSITIVITY = 0.0005;
|
15
|
+
const MAX_ZOOM = 5;
|
16
|
+
const MIN_ZOOM = 0.1;
|
17
|
+
|
18
|
+
export const ImageViewer = ({ image }) => {
|
19
|
+
const [offset, setOffset] = useState({ x: 0, y: 0 });
|
20
|
+
const [zoom, setZoom] = useState(1);
|
21
|
+
const [draggind, setDragging] = useState(false);
|
22
|
+
|
23
|
+
const touch = useRef({ x: 0, y: 0 });
|
24
|
+
const canvasRef = useRef(null);
|
25
|
+
const containerRef = useRef(null);
|
26
|
+
const observer = useRef(null);
|
27
|
+
const background = useMemo(() => new Image(), [image]);
|
28
|
+
|
29
|
+
const clamp = (num, min, max) => Math.min(Math.max(num, min), max);
|
30
|
+
|
31
|
+
const handleWheel = (event) => {
|
32
|
+
const { deltaY } = event;
|
33
|
+
if (!draggind) {
|
34
|
+
setZoom((zoom) =>
|
35
|
+
clamp(zoom + deltaY * SCROLL_SENSITIVITY * -1, MIN_ZOOM, MAX_ZOOM)
|
36
|
+
);
|
37
|
+
}
|
38
|
+
};
|
39
|
+
|
40
|
+
const handleMouseMove = (event) => {
|
41
|
+
if (draggind) {
|
42
|
+
const { x, y } = touch.current;
|
43
|
+
const { clientX, clientY } = event;
|
44
|
+
setOffset({
|
45
|
+
x: offset.x + (x - clientX),
|
46
|
+
y: offset.y + (y - clientY),
|
47
|
+
});
|
48
|
+
touch.current = { x: clientX, y: clientY };
|
49
|
+
}
|
50
|
+
};
|
51
|
+
|
52
|
+
const handleMouseDown = (event) => {
|
53
|
+
const { clientX, clientY } = event;
|
54
|
+
touch.current = { x: clientX, y: clientY };
|
55
|
+
setDragging(true);
|
56
|
+
};
|
57
|
+
|
58
|
+
const handleMouseUp = () => setDragging(false);
|
59
|
+
|
60
|
+
const draw = () => {
|
61
|
+
if (canvasRef.current) {
|
62
|
+
const { width, height } = canvasRef.current;
|
63
|
+
const context = canvasRef.current.getContext("2d");
|
64
|
+
|
65
|
+
// Set canvas dimensions
|
66
|
+
canvasRef.current.width = width;
|
67
|
+
canvasRef.current.height = height;
|
68
|
+
|
69
|
+
// Clear canvas and scale it
|
70
|
+
context.translate(-offset.x, -offset.y);
|
71
|
+
context.scale(zoom, zoom);
|
72
|
+
context.clearRect(0, 0, width, height);
|
73
|
+
|
74
|
+
// Make sure we're zooming to the center
|
75
|
+
const x = (context.canvas.width / zoom - background.width) / 2;
|
76
|
+
const y = (context.canvas.height / zoom - background.height) / 2;
|
77
|
+
|
78
|
+
// Draw image
|
79
|
+
context.drawImage(background, x, y);
|
80
|
+
}
|
81
|
+
};
|
82
|
+
|
83
|
+
useEffect(() => {
|
84
|
+
observer.current = new ResizeObserver((entries) => {
|
85
|
+
entries.forEach(({ target }) => {
|
86
|
+
const { width, height } = background;
|
87
|
+
// If width of the container is smaller than image, scale image down
|
88
|
+
if (target.clientWidth < width) {
|
89
|
+
// Calculate scale
|
90
|
+
const scale = target.clientWidth / width;
|
91
|
+
|
92
|
+
// Redraw image
|
93
|
+
canvasRef.current.width = width * scale;
|
94
|
+
canvasRef.current.height = height * scale;
|
95
|
+
canvasRef.current
|
96
|
+
.getContext("2d")
|
97
|
+
.drawImage(background, 0, 0, width * scale, height * scale);
|
98
|
+
}
|
99
|
+
});
|
100
|
+
});
|
101
|
+
observer.current.observe(containerRef.current);
|
102
|
+
|
103
|
+
return () => observer.current.unobserve(containerRef.current);
|
104
|
+
}, []);
|
105
|
+
|
106
|
+
useEffect(() => {
|
107
|
+
background.src = image;
|
108
|
+
|
109
|
+
if (canvasRef.current) {
|
110
|
+
background.onload = () => {
|
111
|
+
// Get the image dimensions
|
112
|
+
const { width, height } = background;
|
113
|
+
canvasRef.current.width = width;
|
114
|
+
canvasRef.current.height = height;
|
115
|
+
|
116
|
+
// Set image as background
|
117
|
+
canvasRef.current.getContext("2d").drawImage(background, 0, 0);
|
118
|
+
};
|
119
|
+
}
|
120
|
+
}, [background]);
|
121
|
+
|
122
|
+
useEffect(() => {
|
123
|
+
draw();
|
124
|
+
}, [zoom, offset]);
|
125
|
+
|
126
|
+
return (
|
127
|
+
<div ref={containerRef}>
|
128
|
+
<canvas
|
129
|
+
onMouseDown={handleMouseDown}
|
130
|
+
onMouseUp={handleMouseUp}
|
131
|
+
onWheel={handleWheel}
|
132
|
+
onMouseMove={handleMouseMove}
|
133
|
+
ref={canvasRef}
|
134
|
+
/>
|
135
|
+
</div>
|
136
|
+
);
|
137
|
+
};
|
138
|
+
|
139
|
+
|
140
|
+
export default ImageViewer;
|
package/src/widgets/index.js
CHANGED