@webstudio-is/sdk-components-react 0.71.0 → 0.73.0
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.
- package/lib/__generated__/button.props.js +0 -6
- package/lib/__generated__/image.props.js +0 -1
- package/lib/__generated__/link-block.props.js +1 -7
- package/lib/__generated__/link.props.js +1 -7
- package/lib/__generated__/rich-text-link.props.js +1 -7
- package/lib/__generated__/{radio-button-field.props.js → vimeo-play-button.props.js} +14 -0
- package/lib/__generated__/vimeo-preview-image.props.js +441 -0
- package/lib/__generated__/{checkbox-field.props.js → vimeo-spinner.props.js} +0 -1
- package/lib/__generated__/vimeo.props.js +555 -0
- package/lib/blockquote.ws.js +1 -1
- package/lib/box.js +2 -1
- package/lib/button.js +1 -6
- package/lib/button.ws.js +9 -2
- package/lib/checkbox.ws.js +19 -1
- package/lib/cjs/__generated__/button.props.js +0 -6
- package/lib/cjs/__generated__/image.props.js +0 -1
- package/lib/cjs/__generated__/link-block.props.js +1 -7
- package/lib/cjs/__generated__/link.props.js +1 -7
- package/lib/cjs/__generated__/rich-text-link.props.js +1 -7
- package/lib/cjs/__generated__/{text-block.props.js → text.props.js} +3 -3
- package/lib/cjs/__generated__/{radio-button-field.props.js → vimeo-play-button.props.js} +17 -3
- package/lib/cjs/__generated__/vimeo-preview-image.props.js +461 -0
- package/lib/cjs/__generated__/{checkbox-field.props.js → vimeo-spinner.props.js} +3 -4
- package/lib/cjs/__generated__/vimeo.props.js +575 -0
- package/lib/cjs/blockquote.ws.js +1 -1
- package/lib/cjs/box.js +2 -1
- package/lib/cjs/button.js +1 -6
- package/lib/cjs/button.ws.js +9 -2
- package/lib/cjs/checkbox.ws.js +19 -1
- package/lib/cjs/code-text.ws.js +1 -1
- package/lib/cjs/components.js +11 -9
- package/lib/cjs/heading.ws.js +1 -1
- package/lib/cjs/image.js +3 -3
- package/lib/cjs/image.ws.js +12 -9
- package/lib/cjs/label.ws.js +3 -6
- package/lib/cjs/link.js +1 -1
- package/lib/cjs/link.ws.js +3 -3
- package/lib/cjs/list-item.ws.js +1 -1
- package/lib/cjs/metas.js +11 -9
- package/lib/cjs/paragraph.ws.js +2 -2
- package/lib/cjs/props.js +11 -9
- package/lib/cjs/radio-button.ws.js +19 -1
- package/lib/cjs/rich-text-link.ws.js +3 -10
- package/lib/cjs/span.ws.js +1 -1
- package/lib/cjs/{text-block.js → text.js} +6 -6
- package/lib/cjs/{text-block.ws.js → text.ws.js} +10 -10
- package/lib/cjs/{link-block.js → vimeo-play-button.js} +17 -9
- package/lib/cjs/{link-block.ws.js → vimeo-play-button.ws.js} +13 -22
- package/lib/cjs/vimeo-preview-image.js +40 -0
- package/lib/cjs/{radio-button-field.js → vimeo-preview-image.ws.js} +17 -10
- package/lib/cjs/{checkbox-field.js → vimeo-spinner.js} +16 -8
- package/lib/cjs/{checkbox-field.ws.js → vimeo-spinner.ws.js} +11 -30
- package/lib/cjs/vimeo.js +294 -0
- package/lib/cjs/vimeo.ws.js +345 -0
- package/lib/code-text.ws.js +1 -1
- package/lib/components.js +11 -9
- package/lib/heading.ws.js +1 -1
- package/lib/image.js +6 -5
- package/lib/image.ws.js +12 -9
- package/lib/label.ws.js +4 -7
- package/lib/link.js +3 -3
- package/lib/link.ws.js +3 -3
- package/lib/list-item.ws.js +1 -1
- package/lib/metas.js +52 -50
- package/lib/paragraph.ws.js +2 -2
- package/lib/props.js +52 -50
- package/lib/radio-button.ws.js +19 -1
- package/lib/rich-text-link.ws.js +3 -10
- package/lib/span.ws.js +1 -1
- package/lib/{text-block.js → text.js} +3 -3
- package/lib/{text-block.ws.js → text.ws.js} +7 -7
- package/lib/types/__generated__/vimeo-spinner.props.d.ts +2 -0
- package/lib/types/__generated__/vimeo.props.d.ts +2 -0
- package/lib/types/box.d.ts +1 -1
- package/lib/types/button.d.ts +2 -6
- package/lib/types/button.stories.d.ts +2 -6
- package/lib/types/components.d.ts +5 -4
- package/lib/types/image.d.ts +5 -6
- package/lib/types/image.stories.d.ts +555 -6
- package/lib/types/image.ws.d.ts +8 -0
- package/lib/types/link.d.ts +1 -3
- package/lib/types/link.stories.d.ts +2 -6
- package/lib/types/metas.d.ts +5 -4
- package/lib/types/props.d.ts +5 -4
- package/lib/types/rich-text-link.stories.d.ts +2 -6
- package/lib/types/{text-block.d.ts → text.d.ts} +1 -1
- package/lib/types/{text-block.stories.d.ts → text.stories.d.ts} +1 -1
- package/lib/types/vimeo-play-button.d.ts +4 -0
- package/lib/types/vimeo-play-button.stories.d.ts +5 -0
- package/lib/types/vimeo-preview-image.d.ts +281 -0
- package/lib/types/vimeo-preview-image.stories.d.ts +562 -0
- package/lib/types/vimeo-spinner.d.ts +2 -0
- package/lib/types/vimeo-spinner.stories.d.ts +5 -0
- package/lib/types/{link-block.ws.d.ts → vimeo-spinner.ws.d.ts} +1 -1
- package/lib/types/vimeo.d.ts +73 -0
- package/lib/types/vimeo.stories.d.ts +71 -0
- package/lib/types/vimeo.ws.d.ts +3 -0
- package/lib/vimeo-play-button.js +21 -0
- package/lib/vimeo-play-button.ws.js +26 -0
- package/lib/vimeo-preview-image.js +23 -0
- package/lib/vimeo-preview-image.ws.js +20 -0
- package/lib/vimeo-spinner.js +20 -0
- package/lib/vimeo-spinner.ws.js +25 -0
- package/lib/vimeo.js +282 -0
- package/lib/vimeo.ws.js +327 -0
- package/package.json +9 -7
- package/src/LICENSE +21 -0
- package/src/__generated__/button.props.ts +0 -6
- package/src/__generated__/image.props.ts +0 -1
- package/src/__generated__/link-block.props.ts +1 -7
- package/src/__generated__/link.props.ts +1 -7
- package/src/__generated__/rich-text-link.props.ts +1 -7
- package/src/__generated__/{checkbox-field.props.ts → vimeo-play-button.props.ts} +14 -0
- package/src/__generated__/vimeo-preview-image.props.ts +486 -0
- package/src/__generated__/{radio-button-field.props.ts → vimeo-spinner.props.ts} +0 -1
- package/src/__generated__/vimeo.props.ts +621 -0
- package/src/blockquote.ws.tsx +1 -1
- package/src/box.tsx +1 -1
- package/src/button.tsx +3 -11
- package/src/button.ws.tsx +8 -1
- package/src/checkbox.ws.tsx +19 -1
- package/src/code-text.ws.tsx +1 -1
- package/src/components.ts +5 -4
- package/src/heading.ws.tsx +1 -1
- package/src/image.tsx +6 -5
- package/src/image.ws.tsx +11 -9
- package/src/label.ws.tsx +4 -7
- package/src/link.tsx +5 -11
- package/src/link.ws.tsx +3 -3
- package/src/list-item.ws.tsx +1 -1
- package/src/metas.ts +5 -4
- package/src/paragraph.ws.tsx +2 -2
- package/src/props.ts +5 -4
- package/src/radio-button.ws.tsx +19 -1
- package/src/rich-text-link.ws.tsx +3 -11
- package/src/span.ws.tsx +1 -1
- package/src/text.stories.tsx +16 -0
- package/src/{text-block.tsx → text.tsx} +2 -2
- package/src/{text-block.ws.tsx → text.ws.tsx} +8 -8
- package/src/vimeo-play-button.stories.tsx +17 -0
- package/src/vimeo-play-button.tsx +24 -0
- package/src/vimeo-play-button.ws.ts +29 -0
- package/src/vimeo-preview-image.stories.tsx +17 -0
- package/src/vimeo-preview-image.tsx +30 -0
- package/src/vimeo-preview-image.ws.ts +22 -0
- package/src/vimeo-spinner.stories.tsx +17 -0
- package/src/vimeo-spinner.tsx +25 -0
- package/src/vimeo-spinner.ws.ts +27 -0
- package/src/vimeo.stories.tsx +17 -0
- package/src/vimeo.tsx +430 -0
- package/src/vimeo.ws.ts +331 -0
- package/lib/checkbox-field.js +0 -9
- package/lib/checkbox-field.ws.js +0 -44
- package/lib/cjs/radio-button-field.ws.js +0 -62
- package/lib/link-block.js +0 -10
- package/lib/link-block.ws.js +0 -33
- package/lib/radio-button-field.js +0 -9
- package/lib/radio-button-field.ws.js +0 -44
- package/lib/types/checkbox-field.d.ts +0 -3
- package/lib/types/link-block.d.ts +0 -3
- package/lib/types/link-block.stories.d.ts +0 -13
- package/lib/types/radio-button-field.d.ts +0 -3
- package/src/checkbox-field.tsx +0 -10
- package/src/checkbox-field.ws.tsx +0 -47
- package/src/link-block.stories.tsx +0 -16
- package/src/link-block.tsx +0 -9
- package/src/link-block.ws.tsx +0 -38
- package/src/radio-button-field.tsx +0 -10
- package/src/radio-button-field.ws.tsx +0 -47
- package/src/text-block.stories.tsx +0 -16
- /package/lib/__generated__/{text-block.props.js → text.props.js} +0 -0
- /package/lib/types/__generated__/{checkbox-field.props.d.ts → text.props.d.ts} +0 -0
- /package/lib/types/__generated__/{radio-button-field.props.d.ts → vimeo-play-button.props.d.ts} +0 -0
- /package/lib/types/__generated__/{text-block.props.d.ts → vimeo-preview-image.props.d.ts} +0 -0
- /package/lib/types/{checkbox-field.ws.d.ts → text.ws.d.ts} +0 -0
- /package/lib/types/{radio-button-field.ws.d.ts → vimeo-play-button.ws.d.ts} +0 -0
- /package/lib/types/{text-block.ws.d.ts → vimeo-preview-image.ws.d.ts} +0 -0
- /package/src/__generated__/{text-block.props.ts → text.props.ts} +0 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { type ComponentProps } from "react";
|
|
2
|
+
declare const defaultTag = "div";
|
|
3
|
+
type VimeoPlayerOptions = {
|
|
4
|
+
background?: boolean;
|
|
5
|
+
color?: string;
|
|
6
|
+
controls?: boolean;
|
|
7
|
+
dnt?: boolean;
|
|
8
|
+
interactive_params?: string;
|
|
9
|
+
title?: boolean;
|
|
10
|
+
portrait?: boolean;
|
|
11
|
+
/** The ID or the URL of the video on Vimeo. You must supply one of these values to identify the video. When the video's privacy setting is Private, you must use the URL, and the URL must include the h parameter. For more information, see our introductory guide. */
|
|
12
|
+
url?: string;
|
|
13
|
+
/** Whether to pause the current video when another Vimeo video on the same page starts to play. Set this value to false to permit simultaneous playback of all the videos on the page. This option has no effect if you've disabled cookies in your browser, either through browser settings or with an extension or plugin. */
|
|
14
|
+
autopause?: boolean;
|
|
15
|
+
/** Whether to enable the browser to enter picture-in-picture mode automatically when switching tabs or windows, where supported. */
|
|
16
|
+
autopip?: boolean;
|
|
17
|
+
/** Whether to start playback of the video automatically. This feature might not work on all devices. */
|
|
18
|
+
autoplay?: boolean;
|
|
19
|
+
/** Whether to display the video owner's name. */
|
|
20
|
+
byline?: boolean;
|
|
21
|
+
/** Whether to enable keyboard input to trigger player events. This setting doesn't affect tab control. */
|
|
22
|
+
keyboard?: boolean;
|
|
23
|
+
/** Whether to restart the video automatically after reaching the end. */
|
|
24
|
+
loop?: boolean;
|
|
25
|
+
/** Whether the video is muted upon loading. The true value is required for the autoplay behavior in some browsers. */
|
|
26
|
+
muted?: boolean;
|
|
27
|
+
/** Whether to include the picture-in-picture button among the player controls and enable the picture-in-picture API. */
|
|
28
|
+
pip?: boolean;
|
|
29
|
+
/** Whether the video plays inline on supported mobile devices. To force the device to play the video in fullscreen mode instead, set this value to false. */
|
|
30
|
+
playsinline?: boolean;
|
|
31
|
+
/** For videos on a Vimeo Plus account or higher: the playback quality of the video. Use auto for the best possible quality given available bandwidth and other factors. You can also specify 360p, 540p, 720p, 1080p, 2k, and 4k. */
|
|
32
|
+
quality?: "auto" | "360p" | "540p" | "720p" | "1080p" | "2k" | "4k";
|
|
33
|
+
/** Whether to return a responsive embed code, or one that provides intelligent adjustments based on viewing conditions. We recommend this option for mobile-optimized sites. */
|
|
34
|
+
responsive?: boolean;
|
|
35
|
+
/** Whether the player displays speed controls in the preferences menu and enables the playback rate API. */
|
|
36
|
+
speed?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* The text track to display with the video. Specify the text track by its language code (en), the language code and locale (en-US), or the language code and kind (en.captions). For this argument to work, the video must already have a text track of the given type; see our Help Center or Working with Text Track Uploads for more information.
|
|
39
|
+
* To enable automatically generated closed captions instead, provide the value en-x-autogen. Please note that, at the present time, automatic captions are always in English.
|
|
40
|
+
*/
|
|
41
|
+
texttrack?: string;
|
|
42
|
+
/** Whether the responsive player and transparent background are enabled. */
|
|
43
|
+
transparent?: boolean;
|
|
44
|
+
};
|
|
45
|
+
type PlayerStatus = "initial" | "initialized" | "ready";
|
|
46
|
+
export type VimeoOptions = Omit<VimeoPlayerOptions, "dnt" | "interactive_params" | "background" | "controls" | "color" | "byline" | "title" | "portrait"> & {
|
|
47
|
+
/** Whether the preview image should be loaded from Vimeo API. Ideally don't use it, because it will show up with some delay and will make your site feel slower. */
|
|
48
|
+
showPreview?: boolean;
|
|
49
|
+
/** Whether to prevent the player from tracking session data, including cookies. Keep in mind that setting this argument to true also blocks video stats. */
|
|
50
|
+
doNotTrack?: VimeoPlayerOptions["dnt"];
|
|
51
|
+
/** Key-value pairs representing dynamic parameters that are utilized on interactive videos with live elements, such as title=my-video,subtitle=interactive. */
|
|
52
|
+
interactiveParams?: VimeoPlayerOptions["interactive_params"];
|
|
53
|
+
/** Whether the player is in background mode, which hides the playback controls, enables autoplay, and loops the video. */
|
|
54
|
+
backgroundMode?: VimeoPlayerOptions["background"];
|
|
55
|
+
/** Whether to display the player's interactive elements, including the play bar and sharing buttons. Set this option to false for a chromeless experience. To control playback when the play/pause button is hidden, set autoplay to true, use keyboard controls (which remain active), or implement our player SDK. */
|
|
56
|
+
showControls?: VimeoPlayerOptions["controls"];
|
|
57
|
+
/** A color value of the playback controls, which is normally #00ADEF. The embed settings of the video might override this value. */
|
|
58
|
+
controlsColor?: VimeoPlayerOptions["color"];
|
|
59
|
+
/** Whether to display the video owner's name. */
|
|
60
|
+
showByline?: VimeoPlayerOptions["byline"];
|
|
61
|
+
/** Whether the player displays the title overlay. */
|
|
62
|
+
showTitle?: VimeoPlayerOptions["title"];
|
|
63
|
+
/** Whether to display the video owner's portrait. Only works if either title or byline are also enabled */
|
|
64
|
+
showPortrait?: VimeoPlayerOptions["portrait"];
|
|
65
|
+
};
|
|
66
|
+
type Props = Omit<ComponentProps<typeof defaultTag>, keyof VimeoOptions> & VimeoOptions;
|
|
67
|
+
export declare const Vimeo: import("react").ForwardRefExoticComponent<Omit<Props, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
|
|
68
|
+
export declare const VimeoContext: import("react").Context<{
|
|
69
|
+
previewImageUrl?: URL | undefined;
|
|
70
|
+
onInitPlayer: () => void;
|
|
71
|
+
status: PlayerStatus;
|
|
72
|
+
}>;
|
|
73
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { ComponentStory, ComponentMeta } from "@storybook/react";
|
|
3
|
+
declare const _default: ComponentMeta<import("react").ForwardRefExoticComponent<Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "url" | "transparent" | "loop" | "muted" | "quality" | "showPreview" | "autopause" | "autopip" | "autoplay" | "keyboard" | "pip" | "playsinline" | "responsive" | "speed" | "texttrack" | "doNotTrack" | "interactiveParams" | "backgroundMode" | "showControls" | "controlsColor" | "showByline" | "showTitle" | "showPortrait"> & Omit<{
|
|
4
|
+
background?: boolean | undefined;
|
|
5
|
+
color?: string | undefined;
|
|
6
|
+
controls?: boolean | undefined;
|
|
7
|
+
dnt?: boolean | undefined;
|
|
8
|
+
interactive_params?: string | undefined;
|
|
9
|
+
title?: boolean | undefined;
|
|
10
|
+
portrait?: boolean | undefined;
|
|
11
|
+
url?: string | undefined;
|
|
12
|
+
autopause?: boolean | undefined;
|
|
13
|
+
autopip?: boolean | undefined;
|
|
14
|
+
autoplay?: boolean | undefined;
|
|
15
|
+
byline?: boolean | undefined;
|
|
16
|
+
keyboard?: boolean | undefined;
|
|
17
|
+
loop?: boolean | undefined;
|
|
18
|
+
muted?: boolean | undefined;
|
|
19
|
+
pip?: boolean | undefined;
|
|
20
|
+
playsinline?: boolean | undefined;
|
|
21
|
+
quality?: "auto" | "360p" | "540p" | "720p" | "1080p" | "2k" | "4k" | undefined;
|
|
22
|
+
responsive?: boolean | undefined;
|
|
23
|
+
speed?: boolean | undefined;
|
|
24
|
+
texttrack?: string | undefined;
|
|
25
|
+
transparent?: boolean | undefined;
|
|
26
|
+
}, "title" | "color" | "background" | "controls" | "dnt" | "interactive_params" | "byline" | "portrait"> & {
|
|
27
|
+
showPreview?: boolean | undefined;
|
|
28
|
+
doNotTrack?: boolean | undefined;
|
|
29
|
+
interactiveParams?: string | undefined;
|
|
30
|
+
backgroundMode?: boolean | undefined;
|
|
31
|
+
showControls?: boolean | undefined;
|
|
32
|
+
controlsColor?: string | undefined;
|
|
33
|
+
showByline?: boolean | undefined;
|
|
34
|
+
showTitle?: boolean | undefined;
|
|
35
|
+
showPortrait?: boolean | undefined;
|
|
36
|
+
}, "ref"> & import("react").RefAttributes<HTMLDivElement>>>;
|
|
37
|
+
export default _default;
|
|
38
|
+
export declare const Vimeo: ComponentStory<import("react").ForwardRefExoticComponent<Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "url" | "transparent" | "loop" | "muted" | "quality" | "showPreview" | "autopause" | "autopip" | "autoplay" | "keyboard" | "pip" | "playsinline" | "responsive" | "speed" | "texttrack" | "doNotTrack" | "interactiveParams" | "backgroundMode" | "showControls" | "controlsColor" | "showByline" | "showTitle" | "showPortrait"> & Omit<{
|
|
39
|
+
background?: boolean | undefined;
|
|
40
|
+
color?: string | undefined;
|
|
41
|
+
controls?: boolean | undefined;
|
|
42
|
+
dnt?: boolean | undefined;
|
|
43
|
+
interactive_params?: string | undefined;
|
|
44
|
+
title?: boolean | undefined;
|
|
45
|
+
portrait?: boolean | undefined;
|
|
46
|
+
url?: string | undefined;
|
|
47
|
+
autopause?: boolean | undefined;
|
|
48
|
+
autopip?: boolean | undefined;
|
|
49
|
+
autoplay?: boolean | undefined;
|
|
50
|
+
byline?: boolean | undefined;
|
|
51
|
+
keyboard?: boolean | undefined;
|
|
52
|
+
loop?: boolean | undefined;
|
|
53
|
+
muted?: boolean | undefined;
|
|
54
|
+
pip?: boolean | undefined;
|
|
55
|
+
playsinline?: boolean | undefined;
|
|
56
|
+
quality?: "auto" | "360p" | "540p" | "720p" | "1080p" | "2k" | "4k" | undefined;
|
|
57
|
+
responsive?: boolean | undefined;
|
|
58
|
+
speed?: boolean | undefined;
|
|
59
|
+
texttrack?: string | undefined;
|
|
60
|
+
transparent?: boolean | undefined;
|
|
61
|
+
}, "title" | "color" | "background" | "controls" | "dnt" | "interactive_params" | "byline" | "portrait"> & {
|
|
62
|
+
showPreview?: boolean | undefined;
|
|
63
|
+
doNotTrack?: boolean | undefined;
|
|
64
|
+
interactiveParams?: string | undefined;
|
|
65
|
+
backgroundMode?: boolean | undefined;
|
|
66
|
+
showControls?: boolean | undefined;
|
|
67
|
+
controlsColor?: string | undefined;
|
|
68
|
+
showByline?: boolean | undefined;
|
|
69
|
+
showTitle?: boolean | undefined;
|
|
70
|
+
showPortrait?: boolean | undefined;
|
|
71
|
+
}, "ref"> & import("react").RefAttributes<HTMLDivElement>>>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import {
|
|
3
|
+
forwardRef,
|
|
4
|
+
useContext
|
|
5
|
+
} from "react";
|
|
6
|
+
import { VimeoContext } from "./vimeo";
|
|
7
|
+
import { Button, defaultTag } from "./button";
|
|
8
|
+
const VimeoPlayButton = forwardRef(
|
|
9
|
+
(props, ref) => {
|
|
10
|
+
const vimeoContext = useContext(VimeoContext);
|
|
11
|
+
if (vimeoContext.status !== "initial") {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
return /* @__PURE__ */ jsx(Button, { ...props, onClick: vimeoContext.onInitPlayer, ref });
|
|
15
|
+
}
|
|
16
|
+
);
|
|
17
|
+
VimeoPlayButton.displayName = "VimeoPlayButton";
|
|
18
|
+
export {
|
|
19
|
+
VimeoPlayButton,
|
|
20
|
+
defaultTag
|
|
21
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defaultStates
|
|
3
|
+
} from "@webstudio-is/react-sdk";
|
|
4
|
+
import { props } from "./__generated__/vimeo-play-button.props";
|
|
5
|
+
import { ButtonElementIcon } from "@webstudio-is/icons/svg";
|
|
6
|
+
import { button } from "@webstudio-is/react-sdk/css-normalize";
|
|
7
|
+
const presetStyle = {
|
|
8
|
+
button
|
|
9
|
+
};
|
|
10
|
+
const meta = {
|
|
11
|
+
category: "hidden",
|
|
12
|
+
type: "container",
|
|
13
|
+
invalidAncestors: ["Button"],
|
|
14
|
+
requiredAncestors: ["Vimeo"],
|
|
15
|
+
label: "Play Button",
|
|
16
|
+
icon: ButtonElementIcon,
|
|
17
|
+
presetStyle,
|
|
18
|
+
states: defaultStates
|
|
19
|
+
};
|
|
20
|
+
const propsMeta = {
|
|
21
|
+
props
|
|
22
|
+
};
|
|
23
|
+
export {
|
|
24
|
+
meta,
|
|
25
|
+
propsMeta
|
|
26
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import {
|
|
3
|
+
forwardRef,
|
|
4
|
+
useContext
|
|
5
|
+
} from "react";
|
|
6
|
+
import { Image } from "./image";
|
|
7
|
+
import { VimeoContext } from "./vimeo";
|
|
8
|
+
const base64Preview = `data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkOAMAANIAzr59FiYAAAAASUVORK5CYII=`;
|
|
9
|
+
const VimeoPreviewImage = forwardRef(({ src, ...rest }, ref) => {
|
|
10
|
+
const vimeoContext = useContext(VimeoContext);
|
|
11
|
+
return /* @__PURE__ */ jsx(
|
|
12
|
+
Image,
|
|
13
|
+
{
|
|
14
|
+
...rest,
|
|
15
|
+
src: String(vimeoContext.previewImageUrl ?? src ?? base64Preview),
|
|
16
|
+
ref
|
|
17
|
+
}
|
|
18
|
+
);
|
|
19
|
+
});
|
|
20
|
+
VimeoPreviewImage.displayName = "VimeoPreviewImage";
|
|
21
|
+
export {
|
|
22
|
+
VimeoPreviewImage
|
|
23
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
propsOverrides as imagePropsOverrides,
|
|
3
|
+
propsMeta as imagePropsMeta,
|
|
4
|
+
meta as imageMeta
|
|
5
|
+
} from "./image.ws";
|
|
6
|
+
import { props } from "./__generated__/vimeo-preview-image.props";
|
|
7
|
+
const meta = {
|
|
8
|
+
...imageMeta,
|
|
9
|
+
category: "hidden",
|
|
10
|
+
label: "Preview Image",
|
|
11
|
+
requiredAncestors: ["Vimeo"]
|
|
12
|
+
};
|
|
13
|
+
const propsMeta = {
|
|
14
|
+
props: { ...props, ...imagePropsOverrides },
|
|
15
|
+
initialProps: imagePropsMeta.initialProps
|
|
16
|
+
};
|
|
17
|
+
export {
|
|
18
|
+
meta,
|
|
19
|
+
propsMeta
|
|
20
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import {
|
|
3
|
+
forwardRef,
|
|
4
|
+
useContext
|
|
5
|
+
} from "react";
|
|
6
|
+
import { VimeoContext } from "./vimeo";
|
|
7
|
+
const defaultTag = "div";
|
|
8
|
+
const VimeoSpinner = forwardRef(
|
|
9
|
+
(props, ref) => {
|
|
10
|
+
const vimeoContext = useContext(VimeoContext);
|
|
11
|
+
if (vimeoContext.status !== "initialized") {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
return /* @__PURE__ */ jsx("div", { ...props, ref });
|
|
15
|
+
}
|
|
16
|
+
);
|
|
17
|
+
VimeoSpinner.displayName = "VimeoSpinner";
|
|
18
|
+
export {
|
|
19
|
+
VimeoSpinner
|
|
20
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defaultStates
|
|
3
|
+
} from "@webstudio-is/react-sdk";
|
|
4
|
+
import { props } from "./__generated__/vimeo-spinner.props";
|
|
5
|
+
import { div } from "@webstudio-is/react-sdk/css-normalize";
|
|
6
|
+
import { BoxIcon } from "@webstudio-is/icons/svg";
|
|
7
|
+
const presetStyle = {
|
|
8
|
+
div
|
|
9
|
+
};
|
|
10
|
+
const meta = {
|
|
11
|
+
type: "container",
|
|
12
|
+
icon: BoxIcon,
|
|
13
|
+
states: defaultStates,
|
|
14
|
+
presetStyle,
|
|
15
|
+
category: "hidden",
|
|
16
|
+
label: "Spinner",
|
|
17
|
+
requiredAncestors: ["Vimeo"]
|
|
18
|
+
};
|
|
19
|
+
const propsMeta = {
|
|
20
|
+
props
|
|
21
|
+
};
|
|
22
|
+
export {
|
|
23
|
+
meta,
|
|
24
|
+
propsMeta
|
|
25
|
+
};
|
package/lib/vimeo.js
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { colord } from "colord";
|
|
3
|
+
import {
|
|
4
|
+
forwardRef,
|
|
5
|
+
useState,
|
|
6
|
+
useRef,
|
|
7
|
+
useEffect,
|
|
8
|
+
useContext,
|
|
9
|
+
createContext,
|
|
10
|
+
useMemo
|
|
11
|
+
} from "react";
|
|
12
|
+
import { ReactSdkContext } from "@webstudio-is/react-sdk";
|
|
13
|
+
import { shallowEqual } from "shallow-equal";
|
|
14
|
+
const defaultTag = "div";
|
|
15
|
+
const getUrl = (options) => {
|
|
16
|
+
if (options.url === void 0) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
let url;
|
|
20
|
+
try {
|
|
21
|
+
const userUrl = new URL(options.url);
|
|
22
|
+
url = new URL(IFRAME_CDN);
|
|
23
|
+
url.pathname = `/video${userUrl.pathname}`;
|
|
24
|
+
} catch {
|
|
25
|
+
}
|
|
26
|
+
if (url === void 0) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
let option;
|
|
30
|
+
for (option in options) {
|
|
31
|
+
const value = options[option];
|
|
32
|
+
if (option === "url" || value === void 0) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
url.searchParams.append(option, value.toString());
|
|
36
|
+
}
|
|
37
|
+
url.searchParams.set("autoplay", "true");
|
|
38
|
+
if (typeof options.color === "string") {
|
|
39
|
+
const color = colord(options.color).toHex().replace("#", "");
|
|
40
|
+
url.searchParams.set("color", color);
|
|
41
|
+
}
|
|
42
|
+
if (options.portrait) {
|
|
43
|
+
url.searchParams.set("title", "true");
|
|
44
|
+
}
|
|
45
|
+
if (options.byline) {
|
|
46
|
+
url.searchParams.set("portrait", "true");
|
|
47
|
+
url.searchParams.set("title", "true");
|
|
48
|
+
}
|
|
49
|
+
return url.toString();
|
|
50
|
+
};
|
|
51
|
+
const preconnect = (url) => {
|
|
52
|
+
const link = document.createElement("link");
|
|
53
|
+
link.rel = "preconnect";
|
|
54
|
+
link.href = url;
|
|
55
|
+
link.crossOrigin = "true";
|
|
56
|
+
document.head.append(link);
|
|
57
|
+
};
|
|
58
|
+
let warmed = false;
|
|
59
|
+
const PLAYER_CDN = "https://f.vimeocdn.com";
|
|
60
|
+
const IFRAME_CDN = "https://player.vimeo.com";
|
|
61
|
+
const IMAGE_CDN = "https://i.vimeocdn.com";
|
|
62
|
+
const warmConnections = () => {
|
|
63
|
+
if (warmed) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
preconnect(PLAYER_CDN);
|
|
67
|
+
preconnect(IFRAME_CDN);
|
|
68
|
+
preconnect(IMAGE_CDN);
|
|
69
|
+
warmed = true;
|
|
70
|
+
};
|
|
71
|
+
const createPlayer = (parent, options, callback) => {
|
|
72
|
+
const url = getUrl(options);
|
|
73
|
+
if (url === void 0) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const iframe = document.createElement("iframe");
|
|
77
|
+
iframe.setAttribute(
|
|
78
|
+
"allow",
|
|
79
|
+
"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture;"
|
|
80
|
+
);
|
|
81
|
+
iframe.setAttribute("frameborder", "0");
|
|
82
|
+
iframe.setAttribute("allowfullscreen", "true");
|
|
83
|
+
iframe.setAttribute("src", url);
|
|
84
|
+
iframe.setAttribute(
|
|
85
|
+
"style",
|
|
86
|
+
"position: absolute; width: 100%; height: 100%; opacity: 0; transition: opacity 1s;"
|
|
87
|
+
);
|
|
88
|
+
iframe.addEventListener(
|
|
89
|
+
"load",
|
|
90
|
+
() => {
|
|
91
|
+
iframe.style.opacity = "1";
|
|
92
|
+
callback();
|
|
93
|
+
},
|
|
94
|
+
{ once: true }
|
|
95
|
+
);
|
|
96
|
+
parent.appendChild(iframe);
|
|
97
|
+
return () => {
|
|
98
|
+
iframe.parentElement?.removeChild(iframe);
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
const getVideoId = (url) => {
|
|
102
|
+
try {
|
|
103
|
+
const parsedUrl = new URL(url);
|
|
104
|
+
const id = parsedUrl.pathname.split("/")[1];
|
|
105
|
+
if (id === "" || id == null) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
return id;
|
|
109
|
+
} catch {
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
const loadPreviewImage = async (element, videoUrl) => {
|
|
113
|
+
const videoId = getVideoId(videoUrl);
|
|
114
|
+
const apiUrl = `https://vimeo.com/api/v2/video/${videoId}.json`;
|
|
115
|
+
const response = (await (await fetch(apiUrl)).json())[0];
|
|
116
|
+
const thumbnail = response.thumbnail_large;
|
|
117
|
+
const imgId = thumbnail.substr(thumbnail.lastIndexOf("/") + 1).split("_")[0];
|
|
118
|
+
const imageUrl = new URL(IMAGE_CDN);
|
|
119
|
+
imageUrl.pathname = `/video/${imgId}.webp`;
|
|
120
|
+
imageUrl.searchParams.append("mw", "1100");
|
|
121
|
+
imageUrl.searchParams.append("mh", "619");
|
|
122
|
+
imageUrl.searchParams.append("q", "70");
|
|
123
|
+
return imageUrl;
|
|
124
|
+
};
|
|
125
|
+
const useVimeo = ({
|
|
126
|
+
options,
|
|
127
|
+
renderer,
|
|
128
|
+
showPreview
|
|
129
|
+
}) => {
|
|
130
|
+
const [playerStatus, setPlayerStatus] = useState("initial");
|
|
131
|
+
const elementRef = useRef(null);
|
|
132
|
+
const [previewImageUrl, setPreviewImageUrl] = useState();
|
|
133
|
+
useEffect(() => {
|
|
134
|
+
setPlayerStatus(
|
|
135
|
+
options.autoplay && renderer !== "canvas" ? "initialized" : "initial"
|
|
136
|
+
);
|
|
137
|
+
}, [options.autoplay, renderer]);
|
|
138
|
+
useEffect(() => {
|
|
139
|
+
if (elementRef.current === null || playerStatus === "ready" || options.url === void 0) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (showPreview) {
|
|
143
|
+
loadPreviewImage(elementRef.current, options.url).then(
|
|
144
|
+
setPreviewImageUrl
|
|
145
|
+
);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
setPreviewImageUrl(void 0);
|
|
149
|
+
}, [renderer, showPreview, options.url, playerStatus]);
|
|
150
|
+
const optionsRef = useRef(options);
|
|
151
|
+
const stableOptions = useMemo(() => {
|
|
152
|
+
if (shallowEqual(options, optionsRef.current) === false) {
|
|
153
|
+
optionsRef.current = options;
|
|
154
|
+
}
|
|
155
|
+
return optionsRef.current;
|
|
156
|
+
}, [options]);
|
|
157
|
+
useEffect(() => {
|
|
158
|
+
if (elementRef.current === null || playerStatus === "initial") {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
return createPlayer(elementRef.current, stableOptions, () => {
|
|
162
|
+
setPlayerStatus("ready");
|
|
163
|
+
});
|
|
164
|
+
}, [stableOptions, playerStatus]);
|
|
165
|
+
return { previewImageUrl, playerStatus, setPlayerStatus, elementRef };
|
|
166
|
+
};
|
|
167
|
+
const Vimeo = forwardRef(
|
|
168
|
+
({
|
|
169
|
+
url,
|
|
170
|
+
autoplay = false,
|
|
171
|
+
autopause = true,
|
|
172
|
+
backgroundMode = false,
|
|
173
|
+
showByline = false,
|
|
174
|
+
showControls = true,
|
|
175
|
+
doNotTrack = false,
|
|
176
|
+
keyboard = true,
|
|
177
|
+
loop = false,
|
|
178
|
+
muted = false,
|
|
179
|
+
pip = false,
|
|
180
|
+
playsinline = true,
|
|
181
|
+
showPortrait = true,
|
|
182
|
+
quality = "auto",
|
|
183
|
+
responsive = true,
|
|
184
|
+
speed = false,
|
|
185
|
+
showTitle = false,
|
|
186
|
+
transparent = true,
|
|
187
|
+
showPreview = false,
|
|
188
|
+
autopip,
|
|
189
|
+
controlsColor,
|
|
190
|
+
interactiveParams,
|
|
191
|
+
texttrack,
|
|
192
|
+
children,
|
|
193
|
+
...rest
|
|
194
|
+
}, ref) => {
|
|
195
|
+
const { renderer } = useContext(ReactSdkContext);
|
|
196
|
+
const { previewImageUrl, playerStatus, setPlayerStatus, elementRef } = useVimeo({
|
|
197
|
+
renderer,
|
|
198
|
+
showPreview,
|
|
199
|
+
options: {
|
|
200
|
+
url,
|
|
201
|
+
autoplay,
|
|
202
|
+
autopause,
|
|
203
|
+
keyboard,
|
|
204
|
+
loop,
|
|
205
|
+
muted,
|
|
206
|
+
pip,
|
|
207
|
+
playsinline,
|
|
208
|
+
quality,
|
|
209
|
+
responsive,
|
|
210
|
+
speed,
|
|
211
|
+
transparent,
|
|
212
|
+
portrait: showPortrait,
|
|
213
|
+
byline: showByline,
|
|
214
|
+
title: showTitle,
|
|
215
|
+
color: controlsColor,
|
|
216
|
+
controls: showControls,
|
|
217
|
+
interactive_params: interactiveParams,
|
|
218
|
+
background: backgroundMode,
|
|
219
|
+
dnt: doNotTrack
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
return /* @__PURE__ */ jsx(
|
|
223
|
+
VimeoContext.Provider,
|
|
224
|
+
{
|
|
225
|
+
value: {
|
|
226
|
+
status: playerStatus,
|
|
227
|
+
previewImageUrl,
|
|
228
|
+
onInitPlayer() {
|
|
229
|
+
if (renderer !== "canvas") {
|
|
230
|
+
setPlayerStatus("initialized");
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
children: /* @__PURE__ */ jsx(
|
|
235
|
+
"div",
|
|
236
|
+
{
|
|
237
|
+
...rest,
|
|
238
|
+
ref: (value) => {
|
|
239
|
+
elementRef.current = value;
|
|
240
|
+
if (ref !== null) {
|
|
241
|
+
typeof ref === "function" ? ref(value) : ref.current = value;
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
onPointerOver: () => {
|
|
245
|
+
if (renderer !== "canvas") {
|
|
246
|
+
warmConnections();
|
|
247
|
+
}
|
|
248
|
+
},
|
|
249
|
+
children: url === void 0 ? /* @__PURE__ */ jsx(EmptyState, {}) : children
|
|
250
|
+
}
|
|
251
|
+
)
|
|
252
|
+
}
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
);
|
|
256
|
+
Vimeo.displayName = "Vimeo";
|
|
257
|
+
const EmptyState = () => {
|
|
258
|
+
return /* @__PURE__ */ jsx(
|
|
259
|
+
"div",
|
|
260
|
+
{
|
|
261
|
+
style: {
|
|
262
|
+
display: "flex",
|
|
263
|
+
width: "100%",
|
|
264
|
+
height: "100%",
|
|
265
|
+
alignItems: "center",
|
|
266
|
+
justifyContent: "center",
|
|
267
|
+
fontSize: "1.2em"
|
|
268
|
+
},
|
|
269
|
+
children: "Open the Properties panel and paste a video URL, e.g. https://vimeo.com/831343124."
|
|
270
|
+
}
|
|
271
|
+
);
|
|
272
|
+
};
|
|
273
|
+
const VimeoContext = createContext({
|
|
274
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
275
|
+
onInitPlayer: () => {
|
|
276
|
+
},
|
|
277
|
+
status: "initial"
|
|
278
|
+
});
|
|
279
|
+
export {
|
|
280
|
+
Vimeo,
|
|
281
|
+
VimeoContext
|
|
282
|
+
};
|