ywana-core8 0.0.750 → 0.0.752

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ywana-core8",
3
- "version": "0.0.750",
3
+ "version": "0.0.752",
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"
@@ -351,6 +351,7 @@ export const CollectionTree = (props) => {
351
351
  * Collection Editor
352
352
  */
353
353
  const CollectionEditor = (props) => {
354
+ const site = useContext(SiteContext)
354
355
  const [pageContext, setPageContext] = useContext(PageContext)
355
356
  const { selected } = pageContext
356
357
  const { icon, title, schema, layout, autosave = false, delay = 1000, canDelete, onReload, onChange, patch = false, actions } = props
@@ -401,6 +402,7 @@ const CollectionEditor = (props) => {
401
402
  }
402
403
  if (onChange) onChange(form)
403
404
  setPageContext(Object.assign({}, pageContext))
405
+ site.notify({ title: "Datos Guardados" })
404
406
  }
405
407
 
406
408
  function renderTitle() {
@@ -45,8 +45,6 @@ export const CollectionList = (props) => {
45
45
  }
46
46
  })
47
47
 
48
-
49
-
50
48
  const style = selected ? 'selected' : ''
51
49
 
52
50
  return (
@@ -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,3 @@
1
+ .image-viewer {
2
+ border: solid 2px red;
3
+ }
@@ -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;
@@ -8,4 +8,5 @@ export * from './calendar/Calendar'
8
8
  export * from './planner/Planner'
9
9
  export * from './upload'
10
10
  export * from './explorer/Explorer'
11
- export * from './empty/EmptyMessage'
11
+ export * from './empty/EmptyMessage'
12
+ export * from './image/ImageViewer'