@selfcommunity/react-ui 0.8.1-alpha.3 → 0.9.0-alpha.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/lib/cjs/components/CategoriesPopularWidget/CategoriesPopularWidget.js +1 -1
- package/lib/cjs/components/CategoriesSuggestionWidget/CategoriesSuggestionWidget.js +1 -1
- package/lib/cjs/components/EventInfoWidget/EventInfoWidget.js +6 -4
- package/lib/cjs/components/EventMediaWidget/EventMediaWidget.d.ts +37 -0
- package/lib/cjs/components/EventMediaWidget/EventMediaWidget.js +242 -0
- package/lib/cjs/components/EventMediaWidget/Skeleton.d.ts +2 -0
- package/lib/cjs/components/EventMediaWidget/Skeleton.js +28 -0
- package/lib/cjs/components/EventMediaWidget/TriggerButton.d.ts +15 -0
- package/lib/cjs/components/EventMediaWidget/TriggerButton.js +63 -0
- package/lib/cjs/components/EventMediaWidget/asUploadButton.d.ts +7 -0
- package/lib/cjs/components/EventMediaWidget/asUploadButton.js +25 -0
- package/lib/cjs/components/EventMediaWidget/constants.d.ts +1 -0
- package/lib/cjs/components/EventMediaWidget/constants.js +4 -0
- package/lib/cjs/components/EventMediaWidget/index.d.ts +4 -0
- package/lib/cjs/components/EventMediaWidget/index.js +8 -0
- package/lib/cjs/components/PrivateMessageThreadItem/PrivateMessageThreadItem.js +1 -3
- package/lib/cjs/index.d.ts +6 -5
- package/lib/cjs/index.js +14 -13
- package/lib/cjs/shared/Lightbox/BaseLightbox.d.ts +19 -0
- package/lib/cjs/shared/Lightbox/BaseLightbox.js +35 -0
- package/lib/cjs/shared/Lightbox/Lightbox.d.ts +31 -17
- package/lib/cjs/shared/Lightbox/Lightbox.js +16 -19
- package/lib/cjs/shared/Lightbox/constants.d.ts +1 -0
- package/lib/cjs/shared/Lightbox/constants.js +4 -0
- package/lib/cjs/shared/Lightbox/index.d.ts +4 -2
- package/lib/cjs/shared/Lightbox/index.js +4 -1
- package/lib/cjs/shared/Media/File/DisplayComponent.js +23 -6
- package/lib/cjs/shared/MediaChunkUploader/index.js +13 -11
- package/lib/cjs/utils/hash.d.ts +2 -1
- package/lib/esm/components/CategoriesPopularWidget/CategoriesPopularWidget.js +1 -1
- package/lib/esm/components/CategoriesSuggestionWidget/CategoriesSuggestionWidget.js +1 -1
- package/lib/esm/components/EventInfoWidget/EventInfoWidget.js +6 -4
- package/lib/esm/components/EventMediaWidget/EventMediaWidget.d.ts +37 -0
- package/lib/esm/components/EventMediaWidget/EventMediaWidget.js +239 -0
- package/lib/esm/components/EventMediaWidget/Skeleton.d.ts +2 -0
- package/lib/esm/components/EventMediaWidget/Skeleton.js +22 -0
- package/lib/esm/components/EventMediaWidget/TriggerButton.d.ts +15 -0
- package/lib/esm/components/EventMediaWidget/TriggerButton.js +60 -0
- package/lib/esm/components/EventMediaWidget/asUploadButton.d.ts +7 -0
- package/lib/esm/components/EventMediaWidget/asUploadButton.js +23 -0
- package/lib/esm/components/EventMediaWidget/constants.d.ts +1 -0
- package/lib/esm/components/EventMediaWidget/constants.js +1 -0
- package/lib/esm/components/EventMediaWidget/index.d.ts +4 -0
- package/lib/esm/components/EventMediaWidget/index.js +4 -0
- package/lib/esm/components/PrivateMessageThreadItem/PrivateMessageThreadItem.js +1 -3
- package/lib/esm/index.d.ts +6 -5
- package/lib/esm/index.js +7 -7
- package/lib/esm/shared/Lightbox/BaseLightbox.d.ts +19 -0
- package/lib/esm/shared/Lightbox/BaseLightbox.js +33 -0
- package/lib/esm/shared/Lightbox/Lightbox.d.ts +31 -17
- package/lib/esm/shared/Lightbox/Lightbox.js +15 -19
- package/lib/esm/shared/Lightbox/constants.d.ts +1 -0
- package/lib/esm/shared/Lightbox/constants.js +1 -0
- package/lib/esm/shared/Lightbox/index.d.ts +4 -2
- package/lib/esm/shared/Lightbox/index.js +3 -1
- package/lib/esm/shared/Media/File/DisplayComponent.js +23 -6
- package/lib/esm/shared/MediaChunkUploader/index.js +14 -12
- package/lib/esm/utils/hash.d.ts +2 -1
- package/lib/umd/react-ui.js +1 -1
- package/package.json +6 -6
- package/lib/cjs/shared/Media/File/Lightbox/index.d.ts +0 -28
- package/lib/cjs/shared/Media/File/Lightbox/index.js +0 -37
- package/lib/esm/shared/Media/File/Lightbox/index.d.ts +0 -28
- package/lib/esm/shared/Media/File/Lightbox/index.js +0 -34
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { __rest } from "tslib";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { CircularProgress } from '@mui/material';
|
|
4
|
+
import { styled } from '@mui/material/styles';
|
|
5
|
+
import { useCallback, useState } from 'react';
|
|
6
|
+
import { PhotoSlider } from 'react-photo-view';
|
|
7
|
+
import { PREFIX } from './constants';
|
|
8
|
+
const classes = {
|
|
9
|
+
root: `${PREFIX}-root`
|
|
10
|
+
};
|
|
11
|
+
const Root = styled(PhotoSlider, {
|
|
12
|
+
name: PREFIX,
|
|
13
|
+
slot: 'Root',
|
|
14
|
+
overridesResolver: (_props, styles) => styles.root
|
|
15
|
+
})(() => ({}));
|
|
16
|
+
const BaseLightbox = (props) => {
|
|
17
|
+
const { images = [], index, onClose, visible = true, afterClose, onIndexChange, toolbarRender, toolbarButtons } = props, rest = __rest(props, ["images", "index", "onClose", "visible", "afterClose", "onIndexChange", "toolbarRender", "toolbarButtons"]);
|
|
18
|
+
// STATE
|
|
19
|
+
const [currentImageIndex, setCurrentImageIndex] = useState(index || 0);
|
|
20
|
+
const handleIndexChange = useCallback((index) => {
|
|
21
|
+
onIndexChange === null || onIndexChange === void 0 ? void 0 : onIndexChange(index);
|
|
22
|
+
setCurrentImageIndex(index);
|
|
23
|
+
}, [onIndexChange, setCurrentImageIndex]);
|
|
24
|
+
/**
|
|
25
|
+
* Renders root object
|
|
26
|
+
*/
|
|
27
|
+
return (_jsx(Root, Object.assign({}, rest, { className: classes.root, images: images, visible: visible && index !== -1, index: currentImageIndex, onIndexChange: handleIndexChange, onClose: onClose, afterClose: afterClose, loadingElement: _jsx(CircularProgress, { color: 'primary' }), toolbarRender: toolbarRender
|
|
28
|
+
? toolbarRender
|
|
29
|
+
: () => {
|
|
30
|
+
return toolbarButtons;
|
|
31
|
+
} })));
|
|
32
|
+
};
|
|
33
|
+
export default BaseLightbox;
|
|
@@ -1,19 +1,33 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { SCMediaType } from '@selfcommunity/types/src/types';
|
|
2
|
+
export interface LightboxProps {
|
|
3
|
+
/**
|
|
4
|
+
* Images objs
|
|
5
|
+
* @default []
|
|
6
|
+
*/
|
|
7
|
+
medias: SCMediaType[];
|
|
8
|
+
/**
|
|
9
|
+
* Obj index
|
|
10
|
+
* @default 0
|
|
11
|
+
*/
|
|
12
|
+
index: number;
|
|
13
|
+
/**
|
|
14
|
+
* Toolbar
|
|
15
|
+
* @default undefined
|
|
16
|
+
*/
|
|
17
|
+
toolbarButtons?: JSX.Element;
|
|
18
|
+
/**
|
|
19
|
+
* Handles on close
|
|
20
|
+
* @default () => void
|
|
21
|
+
*/
|
|
22
|
+
onClose: () => void;
|
|
23
|
+
/**
|
|
24
|
+
* Handles on index change
|
|
25
|
+
* @default undefined
|
|
26
|
+
*/
|
|
12
27
|
onIndexChange?: (index: number) => void;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Any other properties
|
|
30
|
+
*/
|
|
31
|
+
[p: string]: any;
|
|
17
32
|
}
|
|
18
|
-
|
|
19
|
-
export default ReactImageLightbox;
|
|
33
|
+
export default function Lightbox(props: LightboxProps): JSX.Element;
|
|
@@ -1,28 +1,24 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
|
-
import { jsx as _jsx
|
|
3
|
-
import { useState } from 'react';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
3
|
import { styled } from '@mui/material/styles';
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
|
|
4
|
+
import { useCallback } from 'react';
|
|
5
|
+
import BaseLightbox from './BaseLightbox';
|
|
6
|
+
import { PREFIX } from './constants';
|
|
8
7
|
const classes = {
|
|
9
|
-
root: `${PREFIX}-root`
|
|
8
|
+
root: `${PREFIX}-lightbox-root`
|
|
10
9
|
};
|
|
11
|
-
const Root = styled(
|
|
10
|
+
const Root = styled(BaseLightbox, {
|
|
12
11
|
name: PREFIX,
|
|
13
|
-
slot: '
|
|
14
|
-
overridesResolver: (props, styles) => styles.root
|
|
12
|
+
slot: 'LightboxRoot'
|
|
15
13
|
})(() => ({}));
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
14
|
+
export default function Lightbox(props) {
|
|
15
|
+
// PROPS
|
|
16
|
+
const { medias = [], index = 0, toolbarButtons, onClose, onIndexChange } = props, rest = __rest(props, ["medias", "index", "toolbarButtons", "onClose", "onIndexChange"]);
|
|
17
|
+
const mediaToDataTypeMap = useCallback((media, index) => {
|
|
18
|
+
return { src: media.image, width: media.image_width, height: media.image_height, key: index };
|
|
19
|
+
}, []);
|
|
21
20
|
/**
|
|
22
21
|
* Renders root object
|
|
23
22
|
*/
|
|
24
|
-
return (_jsx(Root, Object.assign({}, rest, { className: classes.root, images:
|
|
25
|
-
|
|
26
|
-
} })));
|
|
27
|
-
};
|
|
28
|
-
export default ReactImageLightbox;
|
|
23
|
+
return (_jsx(Root, Object.assign({}, rest, { className: classes.root, images: medias.map(mediaToDataTypeMap), visible: index !== -1, onClose: onClose, index: index, onIndexChange: onIndexChange, toolbarButtons: toolbarButtons })));
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const PREFIX = "SCLightbox";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const PREFIX = 'SCLightbox';
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import BaseLightbox, { BaseLightboxProps } from './BaseLightbox';
|
|
2
|
+
import Lightbox, { LightboxProps } from './Lightbox';
|
|
3
|
+
export default BaseLightbox;
|
|
4
|
+
export { BaseLightboxProps, Lightbox, LightboxProps };
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
2
|
+
import { Box, Grid, IconButton, Typography } from '@mui/material';
|
|
3
|
+
import Icon from '@mui/material/Icon';
|
|
3
4
|
import { styled } from '@mui/material/styles';
|
|
4
|
-
import
|
|
5
|
-
import { Box, Grid, Typography } from '@mui/material';
|
|
5
|
+
import { Link } from '@selfcommunity/react-core';
|
|
6
6
|
import classNames from 'classnames';
|
|
7
|
-
import
|
|
7
|
+
import { MEDIA_TYPE_DOCUMENT } from '../../../constants/Media';
|
|
8
|
+
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
8
9
|
import { useInView } from 'react-intersection-observer';
|
|
10
|
+
import { Lightbox } from '../../Lightbox';
|
|
9
11
|
import { PREFIX } from './constants';
|
|
10
12
|
import filter from './filter';
|
|
11
13
|
const classes = {
|
|
@@ -27,18 +29,20 @@ const classes = {
|
|
|
27
29
|
const Root = styled(Box, {
|
|
28
30
|
name: PREFIX,
|
|
29
31
|
slot: 'DisplayRoot'
|
|
30
|
-
})(({
|
|
32
|
+
})(({}) => ({}));
|
|
31
33
|
export default (props) => {
|
|
32
34
|
// PROPS
|
|
33
35
|
const { className = '', medias = [], maxVisible = 5, gallery = true, onMediaClick = null } = props;
|
|
34
36
|
// STATE
|
|
35
37
|
const [preview, setPreview] = useState(-1);
|
|
38
|
+
const [toolbarButtons, setToolbarButtons] = useState(undefined);
|
|
36
39
|
const { ref, inView } = useInView({ triggerOnce: false });
|
|
37
40
|
// MEMO
|
|
38
41
|
const _medias = useMemo(() => medias.filter(filter), [medias]);
|
|
39
42
|
// HANDLERS
|
|
40
43
|
const handleClose = () => {
|
|
41
44
|
setPreview(-1);
|
|
45
|
+
setToolbarButtons(undefined);
|
|
42
46
|
};
|
|
43
47
|
// UTILS
|
|
44
48
|
const getImageUrl = (image, original = false) => {
|
|
@@ -110,6 +114,19 @@ export default (props) => {
|
|
|
110
114
|
more && (_jsx("div", Object.assign({ className: classes.coverText, style: { fontSize: '200%' } }, { children: _jsxs("p", { children: ["+", extra] }) }), "count-sub"))
|
|
111
115
|
];
|
|
112
116
|
};
|
|
117
|
+
const handleIndexChange = useCallback((index) => {
|
|
118
|
+
if (_medias[index].type === MEDIA_TYPE_DOCUMENT) {
|
|
119
|
+
setToolbarButtons(_jsx(IconButton, Object.assign({ component: Link, to: medias[index].url, target: "_blank", color: "inherit" }, { children: _jsx(Icon, { children: "download" }) })));
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
setToolbarButtons(undefined);
|
|
123
|
+
}
|
|
124
|
+
}, [_medias, setToolbarButtons]);
|
|
125
|
+
useEffect(() => {
|
|
126
|
+
if (preview !== -1) {
|
|
127
|
+
handleIndexChange(preview);
|
|
128
|
+
}
|
|
129
|
+
}, [preview]);
|
|
113
130
|
const imagesToShow = [..._medias];
|
|
114
131
|
if (maxVisible && _medias.length > maxVisible) {
|
|
115
132
|
imagesToShow.length = maxVisible;
|
|
@@ -117,5 +134,5 @@ export default (props) => {
|
|
|
117
134
|
if (_medias.length === 0) {
|
|
118
135
|
return null;
|
|
119
136
|
}
|
|
120
|
-
return (_jsxs(Root, Object.assign({ className: classNames(classes.displayRoot, className) }, { children: [[1, 3, 4].includes(imagesToShow.length) && renderOne(), imagesToShow.length >= 2 && imagesToShow.length != 4 && renderTwo(), imagesToShow.length >= 4 && renderThree(), preview !== -1 && _jsx(Lightbox, { onClose: handleClose, index: preview, medias: _medias })] })));
|
|
137
|
+
return (_jsxs(Root, Object.assign({ className: classNames(classes.displayRoot, className) }, { children: [[1, 3, 4].includes(imagesToShow.length) && renderOne(), imagesToShow.length >= 2 && imagesToShow.length != 4 && renderTwo(), imagesToShow.length >= 4 && renderThree(), preview !== -1 && (_jsx(Lightbox, { onClose: handleClose, index: preview, medias: _medias, toolbarButtons: toolbarButtons, onIndexChange: handleIndexChange }))] })));
|
|
121
138
|
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
|
-
import { useChunkFinishListener, useChunkStartListener, useItemErrorListener, useItemFinishListener, useRequestPreSend
|
|
2
|
+
import { useChunkFinishListener, useChunkStartListener, useItemErrorListener, useItemFinishListener, useRequestPreSend } from '@rpldy/chunked-uploady';
|
|
3
|
+
import { useItemProgressListener, useItemStartListener } from '@rpldy/uploady';
|
|
3
4
|
import { Endpoints, http } from '@selfcommunity/api-services';
|
|
4
5
|
import { useSCContext, useSCUser } from '@selfcommunity/react-core';
|
|
5
|
-
import {
|
|
6
|
-
import { md5 } from '../../utils/hash';
|
|
6
|
+
import { Logger, resizeImage } from '@selfcommunity/utils';
|
|
7
7
|
import React, { useEffect, useRef, useState } from 'react';
|
|
8
8
|
import { useIntl } from 'react-intl';
|
|
9
|
-
import messages from '../../messages/common';
|
|
10
|
-
import { Logger, resizeImage } from '@selfcommunity/utils';
|
|
11
9
|
import { SCOPE_SC_UI } from '../../constants/Errors';
|
|
10
|
+
import messages from '../../messages/common';
|
|
11
|
+
import { md5 } from '../../utils/hash';
|
|
12
12
|
export default (props) => {
|
|
13
13
|
// PROPS
|
|
14
14
|
const { type = null, onSuccess = null, onProgress = null, onError = null } = props;
|
|
@@ -53,7 +53,7 @@ export default (props) => {
|
|
|
53
53
|
// @ts-ignore
|
|
54
54
|
reader.readAsDataURL(item.file);
|
|
55
55
|
}
|
|
56
|
-
chunkStateRef.current.setChunk({ id: item.id, [
|
|
56
|
+
chunkStateRef.current.setChunk({ id: item.id, ['upload_id']: null, completed: 0, name: item.file.name });
|
|
57
57
|
});
|
|
58
58
|
useItemProgressListener((item) => {
|
|
59
59
|
chunkStateRef.current.setChunk({ id: item.id, completed: item.completed });
|
|
@@ -100,7 +100,7 @@ export default (props) => {
|
|
|
100
100
|
sendOptions: {
|
|
101
101
|
paramName: 'image',
|
|
102
102
|
method: Endpoints.ComposerChunkUploadMedia.method,
|
|
103
|
-
formatServerResponse: (response, status,
|
|
103
|
+
formatServerResponse: (response, status, _headers) => __awaiter(void 0, void 0, void 0, function* () {
|
|
104
104
|
if (status === 401) {
|
|
105
105
|
yield refreshSession();
|
|
106
106
|
}
|
|
@@ -109,7 +109,7 @@ export default (props) => {
|
|
|
109
109
|
}
|
|
110
110
|
};
|
|
111
111
|
if (chunkStateRef.current.chunks[data.item.id].upload_id) {
|
|
112
|
-
res.sendOptions.params = { [
|
|
112
|
+
res.sendOptions.params = { ['upload_id']: chunkStateRef.current.chunks[data.item.id].upload_id };
|
|
113
113
|
}
|
|
114
114
|
else {
|
|
115
115
|
chunkStateRef.current.setChunk({ id: data.item.id, type: type || data.sendOptions.paramName });
|
|
@@ -118,12 +118,14 @@ export default (props) => {
|
|
|
118
118
|
});
|
|
119
119
|
useChunkFinishListener((data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
120
120
|
const _data = yield data.uploadData.response.data;
|
|
121
|
-
chunkStateRef.current.setChunk({ id: data.item.id, [
|
|
121
|
+
chunkStateRef.current.setChunk({ id: data.item.id, ['upload_id']: _data.upload_id });
|
|
122
122
|
}));
|
|
123
123
|
useRequestPreSend(({ items, options }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
124
|
-
const destination = ['JWT', 'OAuth'].includes(scContext.settings.session.type)
|
|
125
|
-
|
|
126
|
-
|
|
124
|
+
const destination = ['JWT', 'OAuth'].includes(scContext.settings.session.type)
|
|
125
|
+
? {
|
|
126
|
+
headers: { Authorization: `Bearer ${scContext.settings.session.authToken.accessToken}` }
|
|
127
|
+
}
|
|
128
|
+
: {};
|
|
127
129
|
if (items.length == 0) {
|
|
128
130
|
return Promise.resolve({ options, destination });
|
|
129
131
|
}
|
package/lib/esm/utils/hash.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { BatchFile } from '@rpldy/shared';
|
|
2
|
+
export declare const md5: (file: BatchFile['file'], chunkSize: number, callback: (arg: any) => void) => void;
|