@antscorp/antsomi-ui 1.3.3-beta.89 → 1.3.3-beta.90

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.
@@ -1,11 +1,8 @@
1
1
  import React from 'react';
2
2
  import type { MediaMode } from '.';
3
- interface MediaThumbProps {
3
+ export interface MediaThumbProps {
4
4
  mode: MediaMode;
5
5
  media: any;
6
- index: number;
7
- posters: string[];
8
- onSetPosters: (newPosters: string[]) => void;
9
6
  }
10
- export declare const MediaThumb: React.FC<MediaThumbProps>;
11
- export {};
7
+ declare const _default: React.NamedExoticComponent<MediaThumbProps>;
8
+ export default _default;
@@ -1,31 +1,15 @@
1
- /* eslint-disable jsx-a11y/media-has-caption */
2
1
  // Libraries
3
- import React, { useEffect } from 'react';
2
+ import React, { lazy, Suspense, memo } from 'react';
3
+ // Assets
4
+ import PlaceholderImage from '@antscorp/antsomi-ui/es/assets/images/placeholder-image.png';
4
5
  // Styled
5
6
  import { Image } from './styled';
6
- export const MediaThumb = props => {
7
- const { mode, index, media, posters, onSetPosters } = props;
8
- useEffect(() => {
9
- let timer = null;
10
- if (mode === 'video' && posters[index] !== '') {
11
- const newPosters = [...posters];
12
- newPosters.splice(index, 1, '');
13
- timer = setTimeout(() => {
14
- onSetPosters(newPosters);
15
- }, 500);
16
- }
17
- return () => {
18
- if (timer) {
19
- clearTimeout(timer);
20
- }
21
- };
22
- }, [mode, posters, index, onSetPosters]);
7
+ const LazyVideoThumbnail = lazy(() => import('./VideoThumbnail'));
8
+ const MediaThumb = props => {
9
+ const { mode, media } = props;
23
10
  if (mode === 'image')
24
11
  return React.createElement(Image, { src: media.url, alt: "img" });
25
- return (React.createElement("video", { controls: false, width: "100%", height: "100%", autoPlay: false, poster: posters[index] || '', onCanPlay: () => {
26
- const newPosters = [...posters];
27
- newPosters.splice(index, 1, '');
28
- onSetPosters(newPosters);
29
- }, style: { position: 'absolute' } },
30
- React.createElement("source", { src: media.url })));
12
+ return (React.createElement(Suspense, { fallback: React.createElement(Image, { src: PlaceholderImage, alt: "img" }) },
13
+ React.createElement(LazyVideoThumbnail, { mode: mode, media: media })));
31
14
  };
15
+ export default memo(MediaThumb);
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import type { MediaThumbProps } from './MediaThumb';
3
+ declare const _default: React.NamedExoticComponent<MediaThumbProps>;
4
+ export default _default;
@@ -0,0 +1,39 @@
1
+ /* eslint-disable jsx-a11y/media-has-caption */
2
+ // Libraries
3
+ import React, { useState, memo, useEffect, useRef } from 'react';
4
+ // Assets
5
+ import PlaceholderImage from '@antscorp/antsomi-ui/es/assets/images/placeholder-image.png';
6
+ // Styled
7
+ import { Image } from './styled';
8
+ const VideoThumbnail = props => {
9
+ const { mode, media } = props;
10
+ const [isShow, setIsShow] = useState(false);
11
+ // Refs
12
+ const videoRef = useRef(null);
13
+ const canvasRef = useRef(null);
14
+ useEffect(() => {
15
+ const canvas = canvasRef.current;
16
+ const video = videoRef.current;
17
+ const dimension = 400;
18
+ let listener = () => { };
19
+ if (media && media.url && mode === 'video') {
20
+ const context = canvas === null || canvas === void 0 ? void 0 : canvas.getContext('2d');
21
+ if (canvas && video && context) {
22
+ listener = () => {
23
+ context.drawImage(video, 0, 0, dimension, dimension);
24
+ setIsShow(true);
25
+ };
26
+ video.addEventListener('loadeddata', listener);
27
+ video.src = media.url;
28
+ }
29
+ }
30
+ return () => {
31
+ video === null || video === void 0 ? void 0 : video.removeEventListener('loadeddata', listener);
32
+ };
33
+ }, [media, mode]);
34
+ return (React.createElement("div", { style: { width: '100%', height: '100%' } },
35
+ React.createElement("video", { width: 400, height: 400, ref: videoRef, style: { display: 'none' } }),
36
+ React.createElement("canvas", { ref: canvasRef, style: { width: '100%', height: '100%', display: isShow ? 'block' : 'none' } }),
37
+ React.createElement(Image, { src: PlaceholderImage, alt: "placeholder", style: { display: isShow ? 'none' : 'block' } })));
38
+ };
39
+ export default memo(VideoThumbnail);
@@ -11,7 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  /* eslint-disable @typescript-eslint/no-use-before-define */
12
12
  /* eslint-disable react-hooks/exhaustive-deps */
13
13
  // Libraries
14
- import React, { useEffect, useState, useRef } from 'react';
14
+ import React, { lazy, Suspense, useEffect, useState, useRef } from 'react';
15
15
  import Upload from 'antd/lib/upload';
16
16
  // Hooks
17
17
  import { useDeepCompareEffect } from '@antscorp/antsomi-ui/es/hooks';
@@ -24,8 +24,6 @@ import { uploadFile, createSavedMedia, deleteSavedMedia, getListingSavedMedia, }
24
24
  import { Button, Icon, Text, message, Spin, Input, Space, } from '@antscorp/antsomi-ui/es/components/atoms';
25
25
  // Molecules
26
26
  import { Modal, InputSearch, Select } from '@antscorp/antsomi-ui/es/components/molecules';
27
- // Components
28
- import { MediaThumb } from './MediaThumb';
29
27
  // Styled
30
28
  import { Boxed, ErrorMessage, Image, Overlay, Paragraph, TextStyled, UploadImageWrapper, WrapperBtn, WrapperIcon, WrapperInputMode, WrapperListImages, } from './styled';
31
29
  // Utils
@@ -49,6 +47,7 @@ const SORT_OPTIONS = {
49
47
  label: 'Sort by Size',
50
48
  },
51
49
  };
50
+ const LazyThumbnail = lazy(() => import('./MediaThumb'));
52
51
  const PATH = '@antscorp/antsomi-ui/es/components/molecules/UploadImage/index.tsx';
53
52
  export const UploadImage = props => {
54
53
  var _a, _b, _c, _d, _e, _f;
@@ -62,7 +61,6 @@ export const UploadImage = props => {
62
61
  const [loading, setLoading] = useState(false);
63
62
  const [isOpenConfirmDelete, setOpenConfirmDelete] = useState(false);
64
63
  const [triggerRefresh, setTriggerRefresh] = useState(1);
65
- const [posters, setPosters] = useState([]);
66
64
  const uploadFilesRef = useRef([]);
67
65
  const uploadFilesTimeoutRef = useRef();
68
66
  const deleteMediaRef = useRef();
@@ -71,12 +69,6 @@ export const UploadImage = props => {
71
69
  setListMedia(storeSavedMedia || []);
72
70
  setLoading(false);
73
71
  }, [storeSavedMedia]);
74
- useDeepCompareEffect(() => {
75
- if (mode === 'video') {
76
- const genPosters = Array.from({ length: (listMedia === null || listMedia === void 0 ? void 0 : listMedia.length) || 0 }, () => PlaceholderImage);
77
- setPosters(genPosters);
78
- }
79
- }, [listMedia]);
80
72
  // When selectedMediaProp onChange
81
73
  useEffect(() => {
82
74
  setSelectedMedia(selectedMediaProp || { url: '' });
@@ -144,7 +136,8 @@ export const UploadImage = props => {
144
136
  var _a;
145
137
  return (React.createElement(WrapperListImages, { className: "ants-group", key: idx },
146
138
  React.createElement(Boxed, null,
147
- React.createElement(MediaThumb, { index: idx, posters: posters, mode: mode, media: media, onSetPosters: setPosters }),
139
+ React.createElement(Suspense, { fallback: React.createElement(Image, { src: PlaceholderImage, alt: "fallback image" }) },
140
+ React.createElement(LazyThumbnail, { mode: mode, media: media })),
148
141
  React.createElement(WrapperBtn, { className: "group-hover" },
149
142
  React.createElement(Button, { onClick: () => handleSelectMedia(media), style: { backgroundColor: 'rgb(255,255,255)' } }, "USE"),
150
143
  React.createElement(Button, { onClick: () => handleRemoveUploadedMedia(media), style: { backgroundColor: 'rgb(255,255,255)' } },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antscorp/antsomi-ui",
3
- "version": "1.3.3-beta.89",
3
+ "version": "1.3.3-beta.90",
4
4
  "description": "An enterprise-class UI design language and React UI library.",
5
5
  "sideEffects": [
6
6
  "dist/*",