@selfcommunity/react-ui 0.8.1-alpha.4 → 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.
Files changed (58) hide show
  1. package/lib/cjs/components/EventMediaWidget/EventMediaWidget.d.ts +37 -0
  2. package/lib/cjs/components/EventMediaWidget/EventMediaWidget.js +242 -0
  3. package/lib/cjs/components/EventMediaWidget/Skeleton.d.ts +2 -0
  4. package/lib/cjs/components/EventMediaWidget/Skeleton.js +28 -0
  5. package/lib/cjs/components/EventMediaWidget/TriggerButton.d.ts +15 -0
  6. package/lib/cjs/components/EventMediaWidget/TriggerButton.js +63 -0
  7. package/lib/cjs/components/EventMediaWidget/asUploadButton.d.ts +7 -0
  8. package/lib/cjs/components/EventMediaWidget/asUploadButton.js +25 -0
  9. package/lib/cjs/components/EventMediaWidget/constants.d.ts +1 -0
  10. package/lib/cjs/components/EventMediaWidget/constants.js +4 -0
  11. package/lib/cjs/components/EventMediaWidget/index.d.ts +4 -0
  12. package/lib/cjs/components/EventMediaWidget/index.js +8 -0
  13. package/lib/cjs/components/PrivateMessageThreadItem/PrivateMessageThreadItem.js +1 -3
  14. package/lib/cjs/index.d.ts +6 -5
  15. package/lib/cjs/index.js +14 -13
  16. package/lib/cjs/shared/Lightbox/BaseLightbox.d.ts +19 -0
  17. package/lib/cjs/shared/Lightbox/BaseLightbox.js +35 -0
  18. package/lib/cjs/shared/Lightbox/Lightbox.d.ts +31 -17
  19. package/lib/cjs/shared/Lightbox/Lightbox.js +16 -19
  20. package/lib/cjs/shared/Lightbox/constants.d.ts +1 -0
  21. package/lib/cjs/shared/Lightbox/constants.js +4 -0
  22. package/lib/cjs/shared/Lightbox/index.d.ts +4 -2
  23. package/lib/cjs/shared/Lightbox/index.js +4 -1
  24. package/lib/cjs/shared/Media/File/DisplayComponent.js +23 -6
  25. package/lib/cjs/shared/MediaChunkUploader/index.js +13 -11
  26. package/lib/cjs/utils/hash.d.ts +2 -1
  27. package/lib/esm/components/EventMediaWidget/EventMediaWidget.d.ts +37 -0
  28. package/lib/esm/components/EventMediaWidget/EventMediaWidget.js +239 -0
  29. package/lib/esm/components/EventMediaWidget/Skeleton.d.ts +2 -0
  30. package/lib/esm/components/EventMediaWidget/Skeleton.js +22 -0
  31. package/lib/esm/components/EventMediaWidget/TriggerButton.d.ts +15 -0
  32. package/lib/esm/components/EventMediaWidget/TriggerButton.js +60 -0
  33. package/lib/esm/components/EventMediaWidget/asUploadButton.d.ts +7 -0
  34. package/lib/esm/components/EventMediaWidget/asUploadButton.js +23 -0
  35. package/lib/esm/components/EventMediaWidget/constants.d.ts +1 -0
  36. package/lib/esm/components/EventMediaWidget/constants.js +1 -0
  37. package/lib/esm/components/EventMediaWidget/index.d.ts +4 -0
  38. package/lib/esm/components/EventMediaWidget/index.js +4 -0
  39. package/lib/esm/components/PrivateMessageThreadItem/PrivateMessageThreadItem.js +1 -3
  40. package/lib/esm/index.d.ts +6 -5
  41. package/lib/esm/index.js +7 -7
  42. package/lib/esm/shared/Lightbox/BaseLightbox.d.ts +19 -0
  43. package/lib/esm/shared/Lightbox/BaseLightbox.js +33 -0
  44. package/lib/esm/shared/Lightbox/Lightbox.d.ts +31 -17
  45. package/lib/esm/shared/Lightbox/Lightbox.js +15 -19
  46. package/lib/esm/shared/Lightbox/constants.d.ts +1 -0
  47. package/lib/esm/shared/Lightbox/constants.js +1 -0
  48. package/lib/esm/shared/Lightbox/index.d.ts +4 -2
  49. package/lib/esm/shared/Lightbox/index.js +3 -1
  50. package/lib/esm/shared/Media/File/DisplayComponent.js +23 -6
  51. package/lib/esm/shared/MediaChunkUploader/index.js +14 -12
  52. package/lib/esm/utils/hash.d.ts +2 -1
  53. package/lib/umd/react-ui.js +1 -1
  54. package/package.json +6 -6
  55. package/lib/cjs/shared/Media/File/Lightbox/index.d.ts +0 -28
  56. package/lib/cjs/shared/Media/File/Lightbox/index.js +0 -37
  57. package/lib/esm/shared/Media/File/Lightbox/index.d.ts +0 -28
  58. 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 React from 'react';
2
- import { DataType } from '../../types/lightbox';
3
- import { PhotoProviderBase } from 'react-photo-view/dist/types';
4
- /**
5
- * Overrides/extends the styles applied to the component.
6
- * @default null
7
- */
8
- export interface ReactImageLightboxProps extends PhotoProviderBase {
9
- className?: string;
10
- images: DataType[];
11
- index?: number;
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
- visible?: boolean;
14
- onClose?: (evt?: React.MouseEvent | React.TouchEvent) => void;
15
- afterClose?: () => void;
16
- toolbarButtons?: React.ReactNode[];
28
+ /**
29
+ * Any other properties
30
+ */
31
+ [p: string]: any;
17
32
  }
18
- declare const ReactImageLightbox: (props: ReactImageLightboxProps) => JSX.Element;
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, Fragment as _Fragment } from "react/jsx-runtime";
3
- import { useState } from 'react';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
4
3
  import { styled } from '@mui/material/styles';
5
- import { PhotoSlider } from 'react-photo-view';
6
- import { CircularProgress } from '@mui/material';
7
- const PREFIX = 'SCLightbox';
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(PhotoSlider, {
10
+ const Root = styled(BaseLightbox, {
12
11
  name: PREFIX,
13
- slot: 'Root',
14
- overridesResolver: (props, styles) => styles.root
12
+ slot: 'LightboxRoot'
15
13
  })(() => ({}));
16
- const ReactImageLightbox = (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 [currentImages] = useState(images || []);
20
- const [currentImageIndex, setCurrentImageIndex] = useState(index || 0);
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: currentImages, visible: visible && index !== -1, index: currentImageIndex, onIndexChange: setCurrentImageIndex, onClose: onClose, afterClose: afterClose, loadingElement: _jsx(CircularProgress, { color: 'primary' }), toolbarRender: toolbarRender ? toolbarRender : () => {
25
- return _jsx(_Fragment, { children: toolbarButtons });
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 Lightbox from './Lightbox';
2
- export default Lightbox;
1
+ import BaseLightbox, { BaseLightboxProps } from './BaseLightbox';
2
+ import Lightbox, { LightboxProps } from './Lightbox';
3
+ export default BaseLightbox;
4
+ export { BaseLightboxProps, Lightbox, LightboxProps };
@@ -1,2 +1,4 @@
1
+ import BaseLightbox from './BaseLightbox';
1
2
  import Lightbox from './Lightbox';
2
- export default Lightbox;
3
+ export default BaseLightbox;
4
+ export { Lightbox };
@@ -1,11 +1,13 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import React, { useCallback, useMemo, useState } from 'react';
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 Lightbox from './Lightbox';
5
- import { Box, Grid, Typography } from '@mui/material';
5
+ import { Link } from '@selfcommunity/react-core';
6
6
  import classNames from 'classnames';
7
- import Icon from '@mui/material/Icon';
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
- })(({ theme }) => ({}));
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, } from '@rpldy/chunked-uploady';
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 { useItemProgressListener, useItemStartListener } from '@rpldy/uploady';
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, [`upload_id`]: null, completed: 0, name: item.file.name });
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, headers) => __awaiter(void 0, void 0, void 0, function* () {
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 = { [`upload_id`]: chunkStateRef.current.chunks[data.item.id].upload_id };
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, [`upload_id`]: _data.upload_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
- headers: { Authorization: `Bearer ${scContext.settings.session.authToken.accessToken}` }
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
  }
@@ -1 +1,2 @@
1
- export declare const md5: (file: any, chunkSize: any, callback: any) => void;
1
+ import { BatchFile } from '@rpldy/shared';
2
+ export declare const md5: (file: BatchFile['file'], chunkSize: number, callback: (arg: any) => void) => void;