-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…-video-block-settings [DEV-7586] Feature - Implement UI for video block settings
- Loading branch information
Showing
17 changed files
with
252 additions
and
65 deletions.
There are no files selected for viewing
35 changes: 26 additions & 9 deletions
35
packages/slate-editor/src/extensions/video/VideoExtension.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
46 changes: 43 additions & 3 deletions
46
packages/slate-editor/src/extensions/video/components/VideoElement.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
9 changes: 9 additions & 0 deletions
9
packages/slate-editor/src/extensions/video/components/VideoMenu.module.scss
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,9 @@ | ||
@import "styles/variables"; | ||
|
||
.icon { | ||
fill: white; | ||
|
||
&.active { | ||
fill: $yellow-300; | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
packages/slate-editor/src/extensions/video/components/VideoMenu.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,107 @@ | ||
import { VideoNode } from '@prezly/slate-types'; | ||
import classNames from 'classnames'; | ||
import React from 'react'; | ||
|
||
import type { OptionsGroupOption } from '#components'; | ||
import { Button, OptionsGroup, Toolbox } from '#components'; | ||
import { | ||
Delete, | ||
ExternalLink, | ||
ImageLayoutContained, | ||
ImageLayoutExpanded, | ||
ImageLayoutFullWidth, | ||
} from '#icons'; | ||
|
||
import styles from './VideoMenu.module.scss'; | ||
|
||
export interface FormState { | ||
layout: VideoNode['layout']; | ||
} | ||
|
||
interface Props { | ||
url: VideoNode['url']; | ||
onChange: (props: Partial<FormState>) => void; | ||
onClose: () => void; | ||
onRemove: () => void; | ||
value: FormState; | ||
withLayoutControls: boolean; | ||
} | ||
|
||
const VIDEO_LAYOUT_OPTIONS: OptionsGroupOption<VideoNode.Layout>[] = [ | ||
{ | ||
value: VideoNode.Layout.CONTAINED, | ||
label: 'Contained', | ||
icon: ({ isActive }) => ( | ||
<ImageLayoutContained | ||
className={classNames(styles.icon, { [styles.active]: isActive })} | ||
/> | ||
), | ||
}, | ||
{ | ||
value: VideoNode.Layout.EXPANDED, | ||
label: 'Expanded', | ||
icon: ({ isActive }) => ( | ||
<ImageLayoutExpanded | ||
className={classNames(styles.icon, { [styles.active]: isActive })} | ||
/> | ||
), | ||
}, | ||
{ | ||
value: VideoNode.Layout.FULL_WIDTH, | ||
label: 'Full width', | ||
icon: ({ isActive }) => ( | ||
<ImageLayoutFullWidth | ||
className={classNames(styles.icon, { [styles.active]: isActive })} | ||
/> | ||
), | ||
}, | ||
]; | ||
|
||
export function VideoMenu({ url, onChange, onClose, onRemove, value, withLayoutControls }: Props) { | ||
const isSelfHosted = | ||
url.startsWith('https://cdn.uc.assets.prezly.com/') || | ||
url.startsWith('https://ucarecdn.com/'); | ||
|
||
return ( | ||
<> | ||
<Toolbox.Header withCloseButton onCloseClick={onClose}> | ||
Video settings | ||
</Toolbox.Header> | ||
|
||
{!isSelfHosted && ( | ||
<Toolbox.Section noPadding> | ||
<Button | ||
type="link" | ||
href={url} | ||
target="_blank" | ||
rel="noreferrer" | ||
icon={ExternalLink} | ||
iconPosition="right" | ||
fullWidth | ||
> | ||
Go to video | ||
</Button> | ||
</Toolbox.Section> | ||
)} | ||
|
||
{withLayoutControls && ( | ||
<Toolbox.Section caption="Size"> | ||
<OptionsGroup | ||
name="layout" | ||
options={VIDEO_LAYOUT_OPTIONS} | ||
selectedValue={value.layout} | ||
onChange={(layout) => { | ||
onChange({ layout }); | ||
}} | ||
/> | ||
</Toolbox.Section> | ||
)} | ||
|
||
<Toolbox.Footer> | ||
<Button variant="clear-faded" icon={Delete} fullWidth onClick={onRemove}> | ||
Remove video | ||
</Button> | ||
</Toolbox.Footer> | ||
</> | ||
); | ||
} |
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
export { VideoExtension, EXTENSION_ID } from './VideoExtension'; | ||
export { EXTENSION_ID, VideoExtension, type VideoExtensionParameters } from './VideoExtension'; | ||
|
||
export { VIDEO_TYPES } from './constants'; | ||
export { createVideoBookmark } from './lib'; | ||
export type { VideoExtensionParameters } from './types'; |
27 changes: 11 additions & 16 deletions
27
packages/slate-editor/src/extensions/video/lib/createVideoBookmark.ts
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 |
---|---|---|
@@ -1,22 +1,17 @@ | ||
import type { VideoNode } from '@prezly/slate-types'; | ||
import { VIDEO_NODE_TYPE } from '@prezly/slate-types'; | ||
import { VideoNode } from '@prezly/slate-types'; | ||
import { v4 as uuidV4 } from 'uuid'; | ||
|
||
type RequiredProps = Pick<VideoNode, 'url' | 'oembed'>; | ||
type OptionaProps = Pick<VideoNode, 'uuid' | 'layout'>; | ||
|
||
function withoutExtraAttributes<T extends VideoNode>(node: T): VideoNode { | ||
const { type, uuid, url, oembed, children, ...extra } = node; | ||
if (Object.keys(extra).length === 0) { | ||
return node; | ||
} | ||
return { type, uuid, url, oembed, children }; | ||
} | ||
|
||
export function createVideoBookmark(props: RequiredProps): VideoNode { | ||
return withoutExtraAttributes({ | ||
uuid: uuidV4(), | ||
...props, | ||
export function createVideoBookmark(props: RequiredProps & Partial<OptionaProps>): VideoNode { | ||
const { uuid = uuidV4(), url, oembed, layout = VideoNode.Layout.CONTAINED } = props; | ||
return { | ||
children: [{ text: '' }], | ||
type: VIDEO_NODE_TYPE, // disallowed to override type | ||
}); | ||
type: VideoNode.TYPE, // disallowed to override type | ||
uuid, | ||
url, | ||
oembed, | ||
layout, | ||
}; | ||
} |
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
5 changes: 2 additions & 3 deletions
5
packages/slate-editor/src/extensions/video/lib/parseSerializedElement.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { removeVideo } from './removeVideo'; | ||
export { updateVideo } from './updateVideo'; |
7 changes: 3 additions & 4 deletions
7
packages/slate-editor/src/extensions/video/transforms/removeVideo.ts
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 |
---|---|---|
@@ -1,10 +1,9 @@ | ||
import { EditorCommands } from '@prezly/slate-commons'; | ||
import type { VideoNode } from '@prezly/slate-types'; | ||
import { isVideoNode } from '@prezly/slate-types'; | ||
import { VideoNode } from '@prezly/slate-types'; | ||
import type { Editor } from 'slate'; | ||
|
||
export function removeVideo(editor: Editor): VideoNode | null { | ||
export function removeVideo(editor: Editor, element?: VideoNode): VideoNode | null { | ||
return EditorCommands.removeNode<VideoNode>(editor, { | ||
match: isVideoNode, | ||
match: element ? (node) => node === element : VideoNode.isVideoNode, | ||
}); | ||
} |
14 changes: 14 additions & 0 deletions
14
packages/slate-editor/src/extensions/video/transforms/updateVideo.ts
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,14 @@ | ||
import type { VideoNode } from '@prezly/slate-types'; | ||
import type { Editor } from 'slate'; | ||
import { Transforms } from 'slate'; | ||
|
||
export function updateVideo( | ||
editor: Editor, | ||
video: VideoNode, | ||
patch: Partial<Pick<VideoNode, 'url' | 'oembed' | 'layout' | 'uuid'>>, | ||
) { | ||
Transforms.setNodes<VideoNode>(editor, patch, { | ||
at: [], | ||
match: (node) => node === video, | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.
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.