@antscorp/antsomi-ui 1.3.5-beta.106 → 1.3.5-beta.108

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,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import type { FormInstance, SelectProps } from 'antd';
3
+ import { ImageSliderProps } from './components';
3
4
  import { ShareAccessProps } from '../ShareAccess/types';
4
5
  export type categoriesProps = {
5
6
  [key: string]: (string | number)[];
@@ -20,29 +21,19 @@ export interface TemplateValueOptions {
20
21
  };
21
22
  accessInfo?: ShareAccessProps['accessInfo'];
22
23
  }
23
- export interface ImagePreviewOptions {
24
- thumbnails: (string | undefined)[];
25
- isLoading?: boolean;
26
- skeleton?: boolean;
27
- previewNavigation?: boolean;
28
- slidesPerView?: number;
29
- hideThumbnailsList?: boolean;
30
- hideDefaultButton?: boolean;
31
- label?: string;
32
- imageWidth?: number;
33
- imageHeight?: number;
34
- }
35
24
  export interface TemplateSaveAsProps {
36
25
  className?: string;
37
26
  shareAccess: Omit<{
38
27
  show: boolean;
39
28
  } & ShareAccessProps, 'accessInfo' | 'onChange'>;
40
- imageReview: ImagePreviewOptions;
29
+ imageReview: {
30
+ label?: string;
31
+ } & Omit<ImageSliderProps, 'defaultThumbnail' | 'onSelectDefault'>;
41
32
  saveOptions?: {
42
33
  saveNewText?: string;
43
34
  saveExistText?: string;
44
- readonly saveNewValue?: string;
45
- readonly saveExistValue?: string;
35
+ saveNewValue?: string;
36
+ saveExistValue?: string;
46
37
  };
47
38
  isLoadingCategories?: boolean;
48
39
  categories?: Array<{
@@ -24,7 +24,7 @@ const { Text } = Typography;
24
24
  export const TemplateSaveAs = props => {
25
25
  const { className, shareAccess, saveOptions, imageReview, isLoadingCategories, categories, omitCategories, templateNames: templateNameList, templateNamesOptions, descriptionOptions, form, value, onChange, onEvent, } = props;
26
26
  const { show: isShowShareAccess } = shareAccess, shareAccessProps = __rest(shareAccess, ["show"]);
27
- const { thumbnails, isLoading: isLoadingThumbnail, skeleton, previewNavigation, slidesPerView, hideThumbnailsList, hideDefaultButton, imageHeight, imageWidth, label: imageReviewLabel, } = imageReview;
27
+ const { label: imageReviewLabel } = imageReview, restImageReviewProps = __rest(imageReview, ["label"]);
28
28
  const { isLoading, label: templateLabel, defaultNewTemplateName = `Untitled Media Template#${dayjs().format('YYYY-MM-DD HH:mm:ss')}`, onSearch, onNamePopupScroll, onScrollToBottom, } = templateNamesOptions || {};
29
29
  const { label: descriptionLabel, placeholder: descriptionPlaceholder } = descriptionOptions || {};
30
30
  const { saveNewText = 'Save as a new media Template', saveExistText = 'Save as an existing media Template', saveNewValue = 'save-new', saveExistValue = 'save-exist', } = saveOptions || {};
@@ -148,7 +148,7 @@ export const TemplateSaveAs = props => {
148
148
  imageReviewLabel || 'Thumbnail template',
149
149
  " ",
150
150
  React.createElement("span", null, "*")),
151
- React.createElement(ImageSlider, { thumbnails: thumbnails, isLoading: isLoadingThumbnail, skeleton: skeleton, previewNavigation: previewNavigation, slidesPerView: slidesPerView, defaultThumbnail: defaultThumbnail, onSelectDefault: value => handleChangeValue({ defaultThumbnail: value }), hideThumbnailsList: hideThumbnailsList, hideDefaultButton: hideDefaultButton, imageHeight: imageHeight, imageWidth: imageWidth })),
151
+ React.createElement(ImageSlider, Object.assign({ defaultThumbnail: defaultThumbnail, onSelectDefault: value => handleChangeValue({ defaultThumbnail: value }) }, restImageReviewProps))),
152
152
  isLoadingCategories ? (React.createElement(Flex, { className: "field-container" },
153
153
  React.createElement(Text, { className: "field-title" }, "Categories"),
154
154
  React.createElement(Space, { style: {
@@ -176,7 +176,7 @@ export const TemplateSaveAs = props => {
176
176
  var _a;
177
177
  const selectedLabel = (_a = parentCategory.children.find(item => item.key === selectedKey)) === null || _a === void 0 ? void 0 : _a.label;
178
178
  return (React.createElement(Flex, { key: selectedKey, className: "selected-category", justify: "space-between", align: "center" },
179
- React.createElement(Tooltip, { title: selectedLabel },
179
+ React.createElement(Tooltip, { title: selectedLabel, zIndex: 3001 },
180
180
  React.createElement(Text, { ellipsis: true, style: { textOverflow: 'ellipsis' } }, selectedLabel)),
181
181
  ' ',
182
182
  React.createElement("span", { className: "remove-btn", onClick: () => handleRemoveCategory({
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ interface BigImageProps {
3
+ url?: string;
4
+ isDefaultThumbnail?: boolean;
5
+ isHideDefaultButton?: boolean;
6
+ index: number;
7
+ onClickDefaultButton?: (index: number) => void;
8
+ }
9
+ export declare const BigImage: React.FC<BigImageProps>;
10
+ export {};
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import { Image } from 'antd';
3
+ import { Button } from '@antscorp/antsomi-ui/es/components';
4
+ import Icon from '@antscorp/icons';
5
+ export const BigImage = React.memo(props => {
6
+ const { url, isDefaultThumbnail, isHideDefaultButton, index, onClickDefaultButton } = props;
7
+ return (React.createElement("div", { className: "image-container--big" },
8
+ url ? React.createElement(Image, { preview: false, width: "80%", height: "96%", src: url }) : null,
9
+ isHideDefaultButton ? null : (React.createElement(Button, { className: "set-default-button", onClick: () => onClickDefaultButton && onClickDefaultButton(index) },
10
+ isDefaultThumbnail ? React.createElement(Icon, { type: "icon-ants-check", style: { fontSize: '12px' } }) : null,
11
+ isDefaultThumbnail ? 'Default thumbnail' : 'Set as default'))));
12
+ });
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- interface ImageSliderProps {
2
+ export interface ImageSliderProps {
3
3
  thumbnails: (string | undefined)[];
4
4
  isLoading?: boolean;
5
5
  className?: string;
@@ -17,4 +17,3 @@ interface ImageSliderProps {
17
17
  onSelectDefault?: (imgIndex: number) => void;
18
18
  }
19
19
  export declare const ImageSlider: React.FC<ImageSliderProps>;
20
- export {};
@@ -1,57 +1,66 @@
1
1
  // Libraries
2
- import React, { useState, useRef } from 'react';
3
- import { Image } from 'antd';
2
+ import React, { useState, useRef, useMemo, useCallback } from 'react';
4
3
  import Icon from '@antscorp/icons';
5
4
  // Components
6
- import { Button, Flex, Spin } from '@antscorp/antsomi-ui/es/components';
5
+ import { Flex, Spin } from '@antscorp/antsomi-ui/es/components';
7
6
  // Styles
8
7
  import { ImageSliderStyled } from './styled';
9
- import clsx from 'clsx';
8
+ import { SmallImage } from './SmallImage';
9
+ import { BigImage } from './BigImage';
10
+ const ButtonSlider = React.memo(({ direction, type, onClick }) => (React.createElement("div", { className: type === 'slider'
11
+ ? `slider-button slider-button--${direction}`
12
+ : `change-preview-button change-preview-button--${direction}`, onClick: onClick },
13
+ React.createElement(Icon, { type: `icon-ants-angle-${direction}` }))));
10
14
  export const ImageSlider = props => {
11
- var _a, _b;
12
15
  const { thumbnails, isLoading, className, skeleton, previewNavigation, slidesPerView = 3, hideThumbnailsList, hideDefaultButton, imageWidth = 330, imageHeight = 230, defaultThumbnail, onSelectDefault, } = props;
13
16
  const sliderContainerRef = useRef(null);
14
17
  const thumbnailSelectedRef = useRef(null);
18
+ const smallImageWidth = useMemo(() => imageWidth / slidesPerView - (10 * (slidesPerView - 1)) / slidesPerView, [imageWidth, slidesPerView]);
15
19
  const [selectedThumbnail, setSelectedThumbnail] = useState(0);
16
20
  const [defaultThumbnailInternal, setDefaultThumbnailInternal] = useState(defaultThumbnail || 0);
17
- (_a = thumbnailSelectedRef.current) === null || _a === void 0 ? void 0 : _a.scrollTo({
18
- left: selectedThumbnail * imageWidth,
19
- behavior: 'smooth',
20
- });
21
- (_b = sliderContainerRef.current) === null || _b === void 0 ? void 0 : _b.scrollTo({
22
- left: selectedThumbnail * (imageWidth / slidesPerView),
23
- behavior: 'smooth',
24
- });
25
- const handleNextThumbnail = () => {
26
- setSelectedThumbnail(prev => (prev === thumbnails.length - 1 ? 0 : prev + 1));
27
- };
28
- const handlePrevThumbnail = () => {
29
- setSelectedThumbnail(prev => (prev === 0 ? thumbnails.length - 1 : prev - 1));
30
- };
31
- return (React.createElement(ImageSliderStyled, { className: className || '', "$skeleton": skeleton, "$slidesPerView": slidesPerView, "$imageWidth": imageWidth, "$imageHeight": imageHeight, vertical: true, gap: 10 },
32
- React.createElement(Flex, { className: "thumbnail-preview-container", ref: thumbnailSelectedRef }, isLoading ? (React.createElement(Spin, { spinning: true })) : (thumbnails.map((url, index) => (React.createElement("div", { key: `image-big_${url}_${index * 2}`, className: clsx('image-container--big', {
33
- 'image-container--default': defaultThumbnailInternal === index,
34
- }) },
35
- url ? (React.createElement(Image, { preview: false, width: "80%", height: "96%", src: thumbnails[index] })) : null,
36
- hideDefaultButton || hideThumbnailsList || thumbnails.length <= 1 ? null : (React.createElement(Button, { className: "set-default-button", onClick: () => {
37
- setDefaultThumbnailInternal(selectedThumbnail);
38
- if (onSelectDefault) {
39
- onSelectDefault(selectedThumbnail);
40
- }
41
- } },
42
- defaultThumbnailInternal === index ? (React.createElement(Icon, { type: "icon-ants-check", style: { fontSize: '12px' } })) : null,
43
- defaultThumbnailInternal === index ? 'Default thumbnail' : 'Set as default'))))))),
44
- hideThumbnailsList || thumbnails.length <= 1 ? null : (React.createElement(Flex, { gap: 10, className: "thumbnail-slider-container", ref: sliderContainerRef }, isLoading ? (React.createElement(Spin, { spinning: true })) : (thumbnails.map((url, index) => (React.createElement("div", { key: `${url}_${index * 2}`, className: clsx('image-container--small', {
45
- 'image-container--selected': index === selectedThumbnail,
46
- }), onClick: () => setSelectedThumbnail(index) }, url ? (React.createElement(Image, { key: url, preview: false, width: "80%", height: "96%", src: url })) : null)))))),
21
+ const handleScroll = useCallback((scrollIndex) => {
22
+ var _a, _b;
23
+ (_a = thumbnailSelectedRef.current) === null || _a === void 0 ? void 0 : _a.scrollTo({
24
+ left: scrollIndex * imageWidth,
25
+ behavior: 'smooth',
26
+ });
27
+ (_b = sliderContainerRef.current) === null || _b === void 0 ? void 0 : _b.scrollTo({
28
+ left: scrollIndex * (smallImageWidth + 10),
29
+ behavior: 'smooth',
30
+ });
31
+ }, [imageWidth, smallImageWidth]);
32
+ const handleNextThumbnail = useCallback(() => {
33
+ setSelectedThumbnail(prev => {
34
+ const newValue = prev === thumbnails.length - 1 ? 0 : prev + 1;
35
+ handleScroll(newValue);
36
+ return newValue;
37
+ });
38
+ }, [thumbnails, handleScroll]);
39
+ const handlePrevThumbnail = useCallback(() => {
40
+ setSelectedThumbnail(prev => {
41
+ const newValue = prev === 0 ? thumbnails.length - 1 : prev - 1;
42
+ handleScroll(newValue);
43
+ return newValue;
44
+ });
45
+ }, [thumbnails, handleScroll]);
46
+ const handleSelectThumbnail = useCallback((index) => {
47
+ handleScroll(index);
48
+ setSelectedThumbnail(index);
49
+ }, [handleScroll]);
50
+ const handleClickDefault = useCallback((index) => {
51
+ // Because of only selectedThumbnail equal to current thumbnail index so can use index instead of selectedThumbnail
52
+ setDefaultThumbnailInternal(index);
53
+ if (onSelectDefault) {
54
+ onSelectDefault(index);
55
+ }
56
+ }, [onSelectDefault]);
57
+ return (React.createElement(ImageSliderStyled, { className: className || '', "$skeleton": skeleton, "$imageWidth": imageWidth, "$smallImageWidth": smallImageWidth, "$imageHeight": imageHeight, vertical: true, gap: 10 },
58
+ React.createElement(Flex, { className: "thumbnail-preview-container", ref: thumbnailSelectedRef }, isLoading ? (React.createElement(Spin, { spinning: true })) : (thumbnails.map((url, index) => (React.createElement(BigImage, { key: `image-big_${url}_${index * 2}`, url: url, index: index, isDefaultThumbnail: defaultThumbnailInternal === index, isHideDefaultButton: hideDefaultButton || hideThumbnailsList || thumbnails.length <= 1, onClickDefaultButton: handleClickDefault }))))),
59
+ hideThumbnailsList || thumbnails.length <= 1 ? null : (React.createElement(Flex, { gap: 10, className: "thumbnail-slider-container", ref: sliderContainerRef }, isLoading ? (React.createElement(Spin, { spinning: true })) : (thumbnails.map((url, index) => (React.createElement(SmallImage, { key: `${url}_${index * 2}`, isSelected: index === selectedThumbnail, url: url, index: index, onClick: handleSelectThumbnail })))))),
47
60
  previewNavigation && !isLoading ? (React.createElement(React.Fragment, null,
48
- React.createElement("div", { className: "change-preview-button change-preview-button--left", onClick: handlePrevThumbnail },
49
- React.createElement(Icon, { type: "icon-ants-angle-left" })),
50
- React.createElement("div", { className: "change-preview-button change-preview-button--right", onClick: handleNextThumbnail },
51
- React.createElement(Icon, { type: "icon-ants-angle-right" })))) : null,
61
+ React.createElement(ButtonSlider, { direction: "left", type: "preview", onClick: handlePrevThumbnail }),
62
+ React.createElement(ButtonSlider, { direction: "right", type: "preview", onClick: handleNextThumbnail }))) : null,
52
63
  hideThumbnailsList || isLoading || thumbnails.length <= 1 ? null : (React.createElement(React.Fragment, null,
53
- React.createElement("div", { className: "slider-button slider-button--left", onClick: handlePrevThumbnail },
54
- React.createElement(Icon, { type: "icon-ants-angle-left" })),
55
- React.createElement("div", { className: "slider-button slider-button--right", onClick: handleNextThumbnail },
56
- React.createElement(Icon, { type: "icon-ants-angle-right" }))))));
64
+ React.createElement(ButtonSlider, { direction: "left", type: "slider", onClick: handlePrevThumbnail }),
65
+ React.createElement(ButtonSlider, { direction: "right", type: "slider", onClick: handleNextThumbnail })))));
57
66
  };
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ interface SmallImageProps {
3
+ url?: string;
4
+ isSelected?: boolean;
5
+ index: number;
6
+ onClick?: (index: number) => void;
7
+ }
8
+ export declare const SmallImage: React.FC<SmallImageProps>;
9
+ export {};
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import { Image } from 'antd';
3
+ export const SmallImage = React.memo(props => {
4
+ const { url, isSelected, index, onClick } = props;
5
+ return (React.createElement("div", { className: `image-container--small ${isSelected ? 'image-container--selected' : ''}`, onClick: () => onClick && onClick(index) }, url ? React.createElement(Image, { preview: false, width: "80%", height: "96%", src: url }) : null));
6
+ });
@@ -1 +1,2 @@
1
1
  export { ImageSlider } from './ImageSlider';
2
+ export type { ImageSliderProps } from './ImageSlider';
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  interface ImageSliderStyledProps {
3
3
  $skeleton?: boolean;
4
- $slidesPerView?: number;
4
+ $smallImageWidth: number;
5
5
  $imageWidth?: number;
6
6
  $imageHeight?: number;
7
7
  }
@@ -151,7 +151,9 @@ export const ImageSliderStyled = styled(Flex) `
151
151
  }
152
152
 
153
153
  &--small {
154
- width: ${props => `calc(100% / ${props.$slidesPerView || 3} - 10px)`};
154
+ box-sizing: border-box;
155
+ width: ${props => `${props.$smallImageWidth}px`};
156
+
155
157
  height: 72px;
156
158
  flex-shrink: 0;
157
159
 
@@ -1 +1,2 @@
1
1
  export { ImageSlider } from './ImageSlider';
2
+ export type { ImageSliderProps } from './ImageSlider';
@@ -14,19 +14,15 @@ export const TemplateSaveAsStyled = styled(Flex) `
14
14
  }
15
15
 
16
16
  .template-container {
17
- width: 698px;
18
- flex-grow: 1;
19
- /* max-height: 567px; */
17
+ flex: 1 1 60%;
20
18
  max-height: 60vh;
21
19
  padding-right: 28px;
22
20
  overflow-y: auto;
23
21
  }
24
22
 
25
23
  .share-access-container {
26
- /* flex: 1; */
27
- width: 270px;
28
- flex-shrink: 0;
29
- padding: 0 28px;
24
+ flex: 1 1 40%;
25
+ padding-left: 28px;
30
26
  max-height: 60vh;
31
27
  overflow-y: auto;
32
28
  border-left: 1px solid #e5e5e5;
@@ -38,7 +34,7 @@ export const TemplateSaveAsStyled = styled(Flex) `
38
34
 
39
35
  .field-title {
40
36
  font-size: 12px;
41
- width: 150px;
37
+ flex: 0 0 150px;
42
38
  span {
43
39
  color: ${(_a = THEME.token) === null || _a === void 0 ? void 0 : _a.red6};
44
40
  }
@@ -1,4 +1,3 @@
1
- import dayjs from 'dayjs';
2
1
  import { TTemplateStatus } from '../types/templateListing';
3
2
  import { Model } from './model';
4
3
  import { TShareAccess } from '../types';
@@ -40,8 +39,8 @@ export declare class ObjectTemplate extends Model<TObjectTemplate> {
40
39
  get settings(): Record<string, any>;
41
40
  get status(): "" | TTemplateStatus;
42
41
  get userId(): number | "";
43
- get createdAt(): "-" | dayjs.Dayjs;
44
- get updatedAt(): "-" | dayjs.Dayjs;
42
+ get createdAt(): string | undefined;
43
+ get updatedAt(): string | undefined;
45
44
  get objectiveTypes(): number[];
46
45
  get networkId(): number | undefined;
47
46
  get thumbnail(): string;
@@ -65,8 +64,8 @@ export declare class ObjectTemplate extends Model<TObjectTemplate> {
65
64
  settings: Record<string, any>;
66
65
  status: string | TTemplateStatus;
67
66
  userId: string | number;
68
- createdAt: string | dayjs.Dayjs;
69
- updatedAt: string | dayjs.Dayjs;
67
+ createdAt: string | undefined;
68
+ updatedAt: string | undefined;
70
69
  objectiveTypes: number[];
71
70
  networkId: number | undefined;
72
71
  thumbnail: string;
@@ -1,9 +1,7 @@
1
- // Libraries
2
- import dayjs from 'dayjs';
3
1
  // Models
4
2
  import { Model } from './model';
5
3
  // Constants
6
- import { DATE_TIME_FORMAT, LAYOUT_TEMPLATE } from '../constants';
4
+ import { LAYOUT_TEMPLATE } from '../constants';
7
5
  export class ObjectTemplate extends Model {
8
6
  get id() {
9
7
  return this.model.template_id || '';
@@ -34,14 +32,10 @@ export class ObjectTemplate extends Model {
34
32
  return this.model.c_user_id || '';
35
33
  }
36
34
  get createdAt() {
37
- return dayjs(this.model.ctime).isValid()
38
- ? dayjs(this.model.ctime, DATE_TIME_FORMAT.DATE_TIME)
39
- : '-';
35
+ return this.model.ctime;
40
36
  }
41
37
  get updatedAt() {
42
- return dayjs(this.model.utime).isValid()
43
- ? dayjs(this.model.utime, DATE_TIME_FORMAT.DATE_TIME)
44
- : '-';
38
+ return this.model.utime;
45
39
  }
46
40
  get objectiveTypes() {
47
41
  return this.model.goal || [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antscorp/antsomi-ui",
3
- "version": "1.3.5-beta.106",
3
+ "version": "1.3.5-beta.108",
4
4
  "description": "An enterprise-class UI design language and React UI library.",
5
5
  "sideEffects": [
6
6
  "dist/*",