-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web): builtin infobox video and markdown block (#1117)
- Loading branch information
Showing
20 changed files
with
239 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
web/src/beta/components/fields/CameraField/CapturePanel/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
web/src/beta/features/Editor/Widgets/ContainerSettingsPanel/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
web/src/beta/features/Visualizer/Crust/Infobox/Block/builtin/Markdown/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { FC, useMemo } from "react"; | ||
import ReactMarkdown from "react-markdown"; | ||
import gfm from "remark-gfm"; | ||
|
||
import BlockWrapper from "@reearth/beta/features/Visualizer/shared/components/BlockWrapper"; | ||
import { CommonBlockProps } from "@reearth/beta/features/Visualizer/shared/types"; | ||
import { ValueTypes } from "@reearth/beta/utils/value"; | ||
import { styled } from "@reearth/services/theme"; | ||
|
||
import { InfoboxBlock } from "../../../types"; | ||
import useExpressionEval from "../useExpressionEval"; | ||
|
||
const plugins = [gfm]; | ||
|
||
const MarkdownBlock: FC<CommonBlockProps<InfoboxBlock>> = ({ block, isSelected, ...props }) => { | ||
const src = useMemo( | ||
() => block?.property?.default?.src?.value as ValueTypes["string"], | ||
[block?.property?.default?.src], | ||
); | ||
|
||
const evaluatedSrc = useExpressionEval(src); | ||
|
||
return ( | ||
<BlockWrapper | ||
name={block?.name} | ||
icon={block?.extensionId} | ||
isSelected={isSelected} | ||
propertyId={block?.propertyId} | ||
property={block?.property} | ||
{...props}> | ||
{evaluatedSrc !== undefined ? ( | ||
<Wrapper> | ||
<ReactMarkdown remarkPlugins={plugins} linkTarget="_blank"> | ||
{evaluatedSrc || ""} | ||
</ReactMarkdown> | ||
</Wrapper> | ||
) : null} | ||
</BlockWrapper> | ||
); | ||
}; | ||
|
||
export default MarkdownBlock; | ||
|
||
const Wrapper = styled("div")(() => ({ | ||
width: "100%", | ||
position: "relative", | ||
["*"]: { | ||
maxWidth: "100%", | ||
height: "auto", | ||
}, | ||
})); |
68 changes: 68 additions & 0 deletions
68
web/src/beta/features/Visualizer/Crust/Infobox/Block/builtin/Video/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { FC, useCallback, useMemo, useState } from "react"; | ||
import Player from "react-player"; | ||
import type ReactPlayer from "react-player"; | ||
|
||
import BlockWrapper from "@reearth/beta/features/Visualizer/shared/components/BlockWrapper"; | ||
import { CommonBlockProps } from "@reearth/beta/features/Visualizer/shared/types"; | ||
import { ValueTypes } from "@reearth/beta/utils/value"; | ||
import { styled } from "@reearth/services/theme"; | ||
|
||
import { InfoboxBlock } from "../../../types"; | ||
import useExpressionEval from "../useExpressionEval"; | ||
|
||
const VideoBlock: FC<CommonBlockProps<InfoboxBlock>> = ({ block, isSelected, ...props }) => { | ||
const [aspectRatio, setAspectRatio] = useState(56.25); | ||
|
||
const src = useMemo( | ||
() => block?.property?.default?.src?.value as ValueTypes["string"], | ||
[block?.property?.default?.src], | ||
); | ||
|
||
const evaluatedSrc = useExpressionEval(src); | ||
|
||
const handleVideoReady = useCallback((player: ReactPlayer) => { | ||
const height = player.getInternalPlayer().videoHeight; | ||
const width = player.getInternalPlayer().videoWidth; | ||
if (!height || !width) return; | ||
setAspectRatio((height / width) * 100); | ||
}, []); | ||
|
||
return ( | ||
<BlockWrapper | ||
name={block?.name} | ||
icon={block?.extensionId} | ||
isSelected={isSelected} | ||
propertyId={block?.propertyId} | ||
property={block?.property} | ||
{...props}> | ||
{evaluatedSrc !== undefined ? ( | ||
<Wrapper aspectRatio={aspectRatio}> | ||
<StyledPlayer | ||
url={evaluatedSrc} | ||
width="100%" | ||
height="100%" | ||
onReady={handleVideoReady} | ||
playsinline | ||
pip | ||
controls | ||
light | ||
/> | ||
</Wrapper> | ||
) : null} | ||
</BlockWrapper> | ||
); | ||
}; | ||
|
||
export default VideoBlock; | ||
|
||
const Wrapper = styled("div")<{ aspectRatio: number }>(({ aspectRatio }) => ({ | ||
position: "relative", | ||
paddingTop: `${aspectRatio}%`, | ||
width: "100%", | ||
})); | ||
|
||
const StyledPlayer = styled(Player)({ | ||
position: "absolute", | ||
top: 0, | ||
left: 0, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
web/src/beta/lib/reearth-ui/components/DragAndDropList/index.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.