Skip to content

Commit

Permalink
feat: support video format at the end operator
Browse files Browse the repository at this point in the history
  • Loading branch information
EiffelFly committed Feb 7, 2024
1 parent 35bfb03 commit 78ffafc
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import cn from "clsx";
import * as React from "react";
import { FieldMode } from "../../type";
import { FieldMode } from "../../types";
import { Icons } from "@instill-ai/design-system";

export const VideoPreview = ({
src,
mode,
className,
}: {
src: string;
mode: FieldMode;
className?: string;
}) => {
const [isPlaying, setIsPlaying] = React.useState(false);
Expand All @@ -34,40 +33,20 @@ export const VideoPreview = ({
/>
{isPlaying ? (
<div className="absolute bottom-0 left-0 right-0 top-0 z-10 flex items-center justify-center">
<PauseIcon className="h-1/3 w-1/3 stroke-white" />
<CustomizePauseIcon className="h-1/3 w-1/3 stroke-white stroke-1" />
</div>
) : (
<div className="absolute bottom-0 left-0 right-0 top-0 z-10 flex items-center justify-center">
<PlayIcon className="h-1/3 w-1/3 stroke-white" />
<CustomizePlayIcon className="h-1/3 w-1/3 stroke-white" />
</div>
)}
</div>
);
};

const PauseIcon = ({ className }: { className?: string }) => {
const CustomizePlayIcon = ({ className }: { className?: string }) => {
return (
<svg
width="80"
height="80"
viewBox="0 0 80 80"
fill="none"
xmlns="http://www.w3.org/2000/svg"
className={className}
>
<path
d="M78.1998 40C78.1998 61.0972 61.0971 78.2 39.9998 78.2C18.9026 78.2 1.79985 61.0972 1.79985 40C1.79985 18.9027 18.9026 1.79996 39.9998 1.79996C61.0971 1.79996 78.1998 18.9027 78.1998 40Z"
strokeWidth="3.6"
/>
</svg>
);
};

const PlayIcon = ({ className }: { className?: string }) => {
return (
<svg
width="80"
height="80"
viewBox="0 0 80 80"
fill="none"
xmlns="http://www.w3.org/2000/svg"
Expand All @@ -89,3 +68,47 @@ const PlayIcon = ({ className }: { className?: string }) => {
</svg>
);
};

const CustomizePauseIcon = ({ className }: { className?: string }) => {
return (
<svg
viewBox="0 0 80 80"
fill="none"
xmlns="http://www.w3.org/2000/svg"
className={className}
>
<g filter="url(#filter0_b_857_30751)">
<path
d="M31.4998 28H28.4998V52H31.4998V28ZM51.4998 28H48.4998V52H51.4998V28ZM78.4998 40C78.4998 61.2629 61.2628 78.5 39.9998 78.5C18.7369 78.5 1.49985 61.2629 1.49985 40C1.49985 18.737 18.7369 1.49996 39.9998 1.49996C61.2628 1.49996 78.4998 18.737 78.4998 40Z"
stroke="white"
stroke-width="3"
/>
</g>
<defs>
<filter
id="filter0_b_857_30751"
x="-19.2002"
y="-19.2"
width="118.4"
height="118.4"
filterUnits="userSpaceOnUse"
color-interpolation-filters="sRGB"
>
<feFlood flood-opacity="0" result="BackgroundImageFix" />
<feGaussianBlur in="BackgroundImageFix" stdDeviation="9.6" />
<feComposite
in2="SourceAlpha"
operator="in"
result="effect1_backgroundBlur_857_30751"
/>
<feBlend
mode="normal"
in="SourceGraphic"
in2="effect1_backgroundBlur_857_30751"
result="shape"
/>
</filter>
</defs>
</svg>
);
};
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./FieldDescriptionTooltip";
export * from "./VideoPreview";
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export const ImagesField = (props: ImagesFieldProps) => {
return (
<FieldRoot title={title} fieldKey={`${title}-field`}>
{images && !hideField ? (
<div className="flex w-full flex-wrap">
{images?.slice(0, 5)?.map((image) => {
<div className="flex w-full flex-wrap gap-2">
{images?.map((image) => {
if (!image) return null;

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Nullable } from "../../../type";
import { ComponentOutputFieldBaseProps } from "../../types";
import { VideoPreview } from "../common";
import { FieldRoot } from "./FieldRoot";

export type VideoFieldProps = {
video: Nullable<string>;
} & ComponentOutputFieldBaseProps;

export const VideoField = (props: VideoFieldProps) => {
const { title, video, hideField } = props;

return (
<FieldRoot title={title} fieldKey={`${title}-field`}>
{!hideField && video ? (
<VideoPreview src={video} className="w-full" />
) : null}
</FieldRoot>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Nullable } from "../../../type";
import { ComponentOutputFieldBaseProps } from "../../types";
import { VideoPreview } from "../common";
import { FieldRoot } from "./FieldRoot";

export type VideosFieldProps = {
videos: Nullable<string>[];
} & ComponentOutputFieldBaseProps;

export const VideosField = (props: VideosFieldProps) => {
const { title, videos, hideField } = props;

return (
<FieldRoot title={title} fieldKey={`${title}-field`}>
{videos && !hideField ? (
<div className="flex w-full flex-wrap gap-2">
{videos.map((video) => {
if (!video) return null;

return (
<VideoPreview
key={`${title}-${video}-field`}
src={video}
className="object-contain"
/>
);
})}
</div>
) : null}
</FieldRoot>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { ObjectField } from "./ObjectField";
import { ObjectsField } from "./ObjectsField";
import { TextField } from "./TextField";
import { TextsField } from "./TextsField";
import { VideoField } from "./VideoField";
import { VideosField } from "./VideosField";

export const ComponentOutputFields = {
AudioField,
Expand All @@ -20,4 +22,6 @@ export const ComponentOutputFields = {
ObjectsField,
TextField,
TextsField,
VideoField,
VideosField,
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { readFileToBinary } from "../../../../view";
import { FieldHead } from "./FieldHead";
import { FileListItem } from "./FileListItem";
import { UploadFileInput } from "./UploadFileInput";
import { StartOperatorFreeFormFieldBaseProps } from "../../type";
import { VideoPreview } from "./VideoPreview";
import { StartOperatorFreeFormFieldBaseProps } from "../../types";
import { VideoPreview } from "../common";

export const VideoField = ({
mode,
Expand Down Expand Up @@ -51,7 +51,6 @@ export const VideoField = ({
{videoFile ? (
<VideoPreview
src={URL.createObjectURL(videoFile)}
mode={mode}
className={mode === "build" ? "h-[150px]" : "h-[360px]"}
/>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { readFileToBinary } from "../../../../view";
import { FieldHead } from "./FieldHead";
import { FileListItem } from "./FileListItem";
import { UploadFileInput } from "./UploadFileInput";
import { StartOperatorFreeFormFieldBaseProps } from "../../type";
import { VideoPreview } from "./VideoPreview";
import { StartOperatorFreeFormFieldBaseProps } from "../../types";
import { VideoPreview } from "../common";

export const VideosField = ({
mode,
Expand Down Expand Up @@ -63,7 +63,6 @@ export const VideosField = ({
<VideoPreview
key={`${path}-${file.name}`}
src={URL.createObjectURL(file)}
mode={mode}
className={
mode === "build"
? "h-[55px] object-cover"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,16 @@ export function pickComponentOutputFieldsFromInstillFormTree(
/>
);
}
case "video": {
return (
<ComponentOutputFields.VideosField
mode={mode}
title={title}
videos={propertyValue}
hideField={hideField}
/>
);
}
case "text": {
return (
<ComponentOutputFields.TextsField
Expand Down Expand Up @@ -268,6 +278,16 @@ export function pickComponentOutputFieldsFromInstillFormTree(
/>
);
}
case "video": {
return (
<ComponentOutputFields.VideoField
mode={mode}
title={title}
video={propertyValue}
hideField={hideField}
/>
);
}
case "image": {
return (
<ComponentOutputFields.ImageField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ export function transformStartOperatorMetadataToZod(
z.array(z.string()).nullable().optional()
);
break;
case "video/*":
zodSchema = zodSchema.setKey(key, z.string().nullable().optional());
break;
case "array:video/*":
zodSchema = zodSchema.setKey(
key,
z.array(z.string()).nullable().optional()
);
break;
case "*/*":
zodSchema = zodSchema.setKey(key, z.string().nullable().optional());
break;
Expand Down

0 comments on commit 78ffafc

Please sign in to comment.