react-editable-photo-grid 2.3.7 → 3.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/README.md +42 -1
- package/dist/index.js +1 -1
- package/package.json +54 -54
- package/src/PhotoGrid.tsx +167 -191
- package/src/components/Checkbox.tsx +26 -26
- package/src/components/NonScrollGallery.tsx +187 -187
- package/src/components/PhotoControls.tsx +60 -60
- package/src/components/RowControls.tsx +32 -32
- package/src/components/ScrollGallery.tsx +212 -189
- package/src/{index.js → index.ts} +5 -5
- package/src/styles.css +416 -443
- package/src/types.ts +81 -77
- package/src/utils.tsx +461 -461
package/src/PhotoGrid.tsx
CHANGED
|
@@ -1,192 +1,168 @@
|
|
|
1
|
-
import React, { cloneElement, useState } from 'react';
|
|
2
|
-
import { PhotoGridProps, PhotoItem, imgSrcProperty } from './types';
|
|
3
|
-
import { sortRow, movePhotoLeft, movePhotoUp, movePhotoDown, movePhotoRight, moveRowUp, moveRowDown, getImageSrcProperty, photoHasDetails } from "./utils";
|
|
4
|
-
import RowControls from './components/RowControls';
|
|
5
|
-
import PhotoControls from './components/PhotoControls';
|
|
6
|
-
import ScrollGallery from './components/ScrollGallery';
|
|
7
|
-
import NonScrollGallery from './components/NonScrollGallery';
|
|
8
|
-
import './styles.css';
|
|
9
|
-
|
|
10
|
-
const PhotoGrid = (props: PhotoGridProps) => {
|
|
11
|
-
const [activeGalleryKey, setActiveGalleryKey] = useState<number>(-1);
|
|
12
|
-
|
|
13
|
-
const handleMovePhotoUp = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
14
|
-
movePhotoUp(e, props);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const handleMovePhotoDown = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
18
|
-
movePhotoDown(e, props);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const handleMovePhotoLeft = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
22
|
-
movePhotoLeft(e, props);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const handleMovePhotoRight = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
26
|
-
movePhotoRight(e, props);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const handleMoveRowUp = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
30
|
-
moveRowUp(e, props);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const handleMoveRowDown = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
34
|
-
moveRowDown(e, props);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const getSrcProperty = (photo: PhotoItem): string => {
|
|
38
|
-
const property = props.imageSrcProperty as string;
|
|
39
|
-
return getImageSrcProperty(photo, property);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const getGalleryKey = (id: string): number => {
|
|
43
|
-
return props.photos.findIndex((photoItem: PhotoItem) => photoItem.id && photoItem.id == id);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const onPhotoClick = (e: React.MouseEvent<HTMLImageElement>): void => {
|
|
47
|
-
const photoId = e.currentTarget.dataset.id;
|
|
48
|
-
if (!photoId) {
|
|
49
|
-
throw new TypeError('Photo id missing');
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (props.onPhotoClick) {
|
|
53
|
-
props.onPhotoClick(e);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (props.useGallery) {
|
|
57
|
-
const imageKey = getGalleryKey(photoId);
|
|
58
|
-
if (imageKey > -1) {
|
|
59
|
-
setActiveGalleryKey(imageKey);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
: null}
|
|
169
|
-
<PhotoControls
|
|
170
|
-
rowKey={row[0]}
|
|
171
|
-
photo={photo}
|
|
172
|
-
movePhotoDown={handleMovePhotoDown}
|
|
173
|
-
movePhotoLeft={handleMovePhotoLeft}
|
|
174
|
-
movePhotoUp={handleMovePhotoUp}
|
|
175
|
-
movePhotoRight={handleMovePhotoRight}
|
|
176
|
-
rowCount={Object.keys(props.rows).length}
|
|
177
|
-
photoCount={row[1].length}
|
|
178
|
-
buttonArrows={props.buttonArrows}
|
|
179
|
-
/>
|
|
180
|
-
</>
|
|
181
|
-
}
|
|
182
|
-
</div>
|
|
183
|
-
)}
|
|
184
|
-
</>
|
|
185
|
-
</div>
|
|
186
|
-
)}
|
|
187
|
-
</div>
|
|
188
|
-
</div>
|
|
189
|
-
);
|
|
190
|
-
};
|
|
191
|
-
|
|
1
|
+
import React, { cloneElement, useState } from 'react';
|
|
2
|
+
import { PhotoGridProps, PhotoItem, imgSrcProperty } from './types';
|
|
3
|
+
import { sortRow, movePhotoLeft, movePhotoUp, movePhotoDown, movePhotoRight, moveRowUp, moveRowDown, getImageSrcProperty, photoHasDetails } from "./utils";
|
|
4
|
+
import RowControls from './components/RowControls';
|
|
5
|
+
import PhotoControls from './components/PhotoControls';
|
|
6
|
+
import ScrollGallery from './components/ScrollGallery';
|
|
7
|
+
import NonScrollGallery from './components/NonScrollGallery';
|
|
8
|
+
import './styles.css';
|
|
9
|
+
|
|
10
|
+
const PhotoGrid = (props: PhotoGridProps) => {
|
|
11
|
+
const [activeGalleryKey, setActiveGalleryKey] = useState<number>(-1);
|
|
12
|
+
|
|
13
|
+
const handleMovePhotoUp = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
14
|
+
movePhotoUp(e, props);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const handleMovePhotoDown = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
18
|
+
movePhotoDown(e, props);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const handleMovePhotoLeft = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
22
|
+
movePhotoLeft(e, props);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const handleMovePhotoRight = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
26
|
+
movePhotoRight(e, props);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const handleMoveRowUp = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
30
|
+
moveRowUp(e, props);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const handleMoveRowDown = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
34
|
+
moveRowDown(e, props);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const getSrcProperty = (photo: PhotoItem): string => {
|
|
38
|
+
const property = props.imageSrcProperty as string;
|
|
39
|
+
return getImageSrcProperty(photo, property);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const getGalleryKey = (id: string): number => {
|
|
43
|
+
return props.photos.findIndex((photoItem: PhotoItem) => photoItem.id && photoItem.id == id);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const onPhotoClick = (e: React.MouseEvent<HTMLImageElement>): void => {
|
|
47
|
+
const photoId = e.currentTarget.dataset.id;
|
|
48
|
+
if (!photoId) {
|
|
49
|
+
throw new TypeError('Photo id missing');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (props.onPhotoClick) {
|
|
53
|
+
props.onPhotoClick(e);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (props.useGallery) {
|
|
57
|
+
const imageKey = getGalleryKey(photoId);
|
|
58
|
+
if (imageKey > -1) {
|
|
59
|
+
setActiveGalleryKey(imageKey);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (Object.keys(props.rows).length === 0) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<div>
|
|
70
|
+
{props.useGallery &&
|
|
71
|
+
props.galleryType === 'scroll' ?
|
|
72
|
+
<ScrollGallery
|
|
73
|
+
photos={props.photos}
|
|
74
|
+
activeKey={activeGalleryKey}
|
|
75
|
+
setActiveKey={setActiveGalleryKey}
|
|
76
|
+
imageSrcPrefix={props.imageSrcPrefix}
|
|
77
|
+
imageSrcProperty={props.gallerySrcProperty ? props.gallerySrcProperty : ('image_path' as imgSrcProperty)}
|
|
78
|
+
buttonArrows={props.galleryButtonArrows}
|
|
79
|
+
onGallerySwipe={props.onGallerySwipe}
|
|
80
|
+
/>
|
|
81
|
+
: <NonScrollGallery
|
|
82
|
+
photos={props.photos}
|
|
83
|
+
activeKey={activeGalleryKey}
|
|
84
|
+
setActiveKey={setActiveGalleryKey}
|
|
85
|
+
imageSrcPrefix={props.imageSrcPrefix}
|
|
86
|
+
imageSrcProperty={props.gallerySrcProperty ? props.gallerySrcProperty : ('image_path' as imgSrcProperty)}
|
|
87
|
+
buttonArrows={props.galleryButtonArrows}
|
|
88
|
+
onGallerySwipe={props.onGallerySwipe}
|
|
89
|
+
/>
|
|
90
|
+
}
|
|
91
|
+
<div className="photogrid">
|
|
92
|
+
{Object.entries(props.rows).map((row, i) =>
|
|
93
|
+
row[1].length &&
|
|
94
|
+
<div
|
|
95
|
+
key={'row-' + i}
|
|
96
|
+
className={props.isEditing ? "photogrid--photo__row editing" : "photogrid--photo__row"}
|
|
97
|
+
>
|
|
98
|
+
<>
|
|
99
|
+
{props.isEditing && (
|
|
100
|
+
<RowControls
|
|
101
|
+
rowKey={row[0]}
|
|
102
|
+
moveRowUp={handleMoveRowUp}
|
|
103
|
+
moveRowDown={handleMoveRowDown}
|
|
104
|
+
rowCount={Object.keys(props.rows).length}
|
|
105
|
+
buttonArrows={props.buttonArrows}
|
|
106
|
+
/>
|
|
107
|
+
)}
|
|
108
|
+
{sortRow(row[1]).map((photo, i2) =>
|
|
109
|
+
<div
|
|
110
|
+
key={'photo-' + i + i2}
|
|
111
|
+
className="photogrid--photo__column"
|
|
112
|
+
>
|
|
113
|
+
<img
|
|
114
|
+
width={photo.width}
|
|
115
|
+
height={photo.height}
|
|
116
|
+
data-id={photo.id}
|
|
117
|
+
src={`${props.imageSrcPrefix}${getSrcProperty(photo)}`}
|
|
118
|
+
alt={photo.thumbnail_path}
|
|
119
|
+
onClick={onPhotoClick}
|
|
120
|
+
className={props.useGallery ? "cursor-pointer" : 'cursor-default'}
|
|
121
|
+
/>
|
|
122
|
+
|
|
123
|
+
{!props.isEditing && photoHasDetails(photo) === true && (
|
|
124
|
+
<div className="photogrid--photo_overlay">
|
|
125
|
+
{photo.name != undefined && photo.name !== '' && (
|
|
126
|
+
<h4>{photo.name}</h4>
|
|
127
|
+
)}
|
|
128
|
+
{photo.description != undefined && photo.description !== '' && (
|
|
129
|
+
<p>{photo.description}</p>
|
|
130
|
+
)}
|
|
131
|
+
</div>
|
|
132
|
+
)}
|
|
133
|
+
{props.isEditing ? (
|
|
134
|
+
<>
|
|
135
|
+
<p className="photo__position">R: {row[0]} | C: {photo.column}</p>
|
|
136
|
+
{props.photoMenu ?
|
|
137
|
+
cloneElement(props.photoMenu, {
|
|
138
|
+
photo: photo
|
|
139
|
+
})
|
|
140
|
+
: null}
|
|
141
|
+
<PhotoControls
|
|
142
|
+
rowKey={row[0]}
|
|
143
|
+
photo={photo}
|
|
144
|
+
movePhotoDown={handleMovePhotoDown}
|
|
145
|
+
movePhotoLeft={handleMovePhotoLeft}
|
|
146
|
+
movePhotoUp={handleMovePhotoUp}
|
|
147
|
+
movePhotoRight={handleMovePhotoRight}
|
|
148
|
+
rowCount={Object.keys(props.rows).length}
|
|
149
|
+
photoCount={row[1].length}
|
|
150
|
+
buttonArrows={props.buttonArrows}
|
|
151
|
+
/>
|
|
152
|
+
</>
|
|
153
|
+
) : props.photoActions ? (
|
|
154
|
+
cloneElement(props.photoActions, {
|
|
155
|
+
photo: photo
|
|
156
|
+
})
|
|
157
|
+
) : null}
|
|
158
|
+
</div>
|
|
159
|
+
)}
|
|
160
|
+
</>
|
|
161
|
+
</div>
|
|
162
|
+
)}
|
|
163
|
+
</div>
|
|
164
|
+
</div>
|
|
165
|
+
);
|
|
166
|
+
};
|
|
167
|
+
|
|
192
168
|
export default PhotoGrid;
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
type props = {
|
|
4
|
-
value: string;
|
|
5
|
-
onClick: (value: string, checked: boolean) => void;
|
|
6
|
-
checked: boolean;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const Checkbox = (props: props) => {
|
|
10
|
-
const toggleCheckbox = (e: React.MouseEvent<HTMLDivElement>): void => {
|
|
11
|
-
e.preventDefault();
|
|
12
|
-
if (props.checked) {
|
|
13
|
-
props.onClick(props.value, false);
|
|
14
|
-
} else {
|
|
15
|
-
props.onClick(props.value, true);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return (
|
|
20
|
-
<div
|
|
21
|
-
className={props.checked ? "photogrid--checkbox active" : "photogrid--checkbox"}
|
|
22
|
-
onClick={toggleCheckbox}
|
|
23
|
-
/>
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
type props = {
|
|
4
|
+
value: string;
|
|
5
|
+
onClick: (value: string, checked: boolean) => void;
|
|
6
|
+
checked: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const Checkbox = (props: props) => {
|
|
10
|
+
const toggleCheckbox = (e: React.MouseEvent<HTMLDivElement>): void => {
|
|
11
|
+
e.preventDefault();
|
|
12
|
+
if (props.checked) {
|
|
13
|
+
props.onClick(props.value, false);
|
|
14
|
+
} else {
|
|
15
|
+
props.onClick(props.value, true);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<div
|
|
21
|
+
className={props.checked ? "photogrid--checkbox active" : "photogrid--checkbox"}
|
|
22
|
+
onClick={toggleCheckbox}
|
|
23
|
+
/>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
27
|
export default Checkbox;
|