├── .gitignore
├── .npmignore
├── LICENSE
├── README.md
├── babel.config.js
├── lib
├── base
│ └── schema
│ │ └── objects
│ │ ├── vimeoOEmbedConfigData.js
│ │ ├── vimeoOEmbedData.js
│ │ └── vimeoVideo.js
└── components
│ └── VimeoInput
│ ├── components
│ ├── ConfigFieldsInput
│ │ ├── components
│ │ │ ├── Switch.js
│ │ │ └── TextInput.js
│ │ ├── constants.js
│ │ └── index.js
│ └── Label
│ │ ├── components
│ │ ├── Description.js
│ │ ├── Label.js
│ │ └── Title.js
│ │ └── index.js
│ ├── index.js
│ └── styles
│ └── VimeoInput.css
├── package-lock.json
├── package.json
└── sanity.json
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 |
6 | # Runtime Data
7 | pids
8 | *.pid
9 | *.seed
10 | *.pid.lock
11 |
12 | # Dependency Directories
13 | node_modules/
14 |
15 | # Optional NPM Cache Directory
16 | .npm
17 |
18 | # Output of 'npm pack'
19 | *.tgz
20 |
21 | # Deployment Directories
22 | dist/
23 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | lib
2 | node_modules
3 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Bradley Griffith
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Sanity Plugin Goth Vimeo Input
2 |
3 | > ???? `sanity-plugin-vimeo-input` was taken so it's named `sanity-plugin-goth-vimeo-input`.
4 |
5 | A Sanity Plugin for Inputting Vimeo Videos by their URL and Pre-Loading oEmbed Data.
6 |
7 | Through this plugin, your users will simply be required to input a valid Vimeo video URL. The plugin will use the [Vimeo oEmbed API](https://developer.vimeo.com/api/oembed) to then verify the video and import the full oEmbed payload for the video, which includes the video's title, ID, iFrame embed code, and thumbnail URL.
8 |
9 | Additionally, the plugin allows the developer to set both defaults and available configuration options for the user to further customize the player included in the oEmbed response (e.g.; setting the video to autoplay or to use custom player control colors).
10 |
11 | 
12 |
13 | ## Install
14 |
15 | While in your Sanity project directory, run the following command:
16 |
17 | ```
18 | sanity install goth-vimeo-input
19 | ```
20 |
21 | You can read more about Sanity Plugin usage in the [official guide](https://www.sanity.io/docs/plugins).
22 |
23 |
24 | ## Usage
25 |
26 | #### Basic
27 |
28 | To have your user simply input a Vimeo URL without additional configuration, you may include the `type`, `vimeoVideo`, in your schema without additional options.
29 |
30 | ```javascript
31 | export default {
32 | name: "video",
33 | title: "Video",
34 | type: "document",
35 | fields: [
36 | {
37 | name: "vimeoVideo",
38 | title: "Vimeo Video",
39 | type: "vimeoVideo",
40 | validation: Rule => Rule.required()
41 | },
42 | ],
43 | preview: {
44 | select: {
45 | vimeoVideo: "vimeoVideo"
46 | },
47 | prepare(selection) {
48 | let oEmbedData = selection.vimeoVideo
49 | ? selection.vimeoVideo.oEmbedData
50 | : {};
51 |
52 | return {
53 | title: oEmbedData.title || ""
54 | }
55 | }
56 | }
57 | };
58 | ```
59 |
60 | See: https://vimeo.com/475247102
61 |
62 | #### With Configuration
63 |
64 | To include additional configuration, you may utilize either or both of the options provided with this plugin: `configurableFields` and `defaultFieldValues`. The `configurableFields` option tells the plugin which of the [Vimeo oEmbed Arguments](https://developer.vimeo.com/api/oembed/videos) to allow your user to set when loading the video, and the `defaultFieldValues` option tells the plugin the default values for any such arguments (whether configurable by the user or not).
65 |
66 | For example, the follow example will expose controls for toggling `autoplay` and `controls` on the player, and set default values for several other important oEmbed arugments:
67 |
68 | ```javascript
69 | export default {
70 | name: "video",
71 | title: "Video",
72 | type: "document",
73 | fields: [
74 | {
75 | name: "vimeoVideo",
76 | title: "Vimeo Video",
77 | type: "vimeoVideo",
78 | options: {
79 | configurableFields: [
80 | "autoplay",
81 | "controls"
82 | ],
83 | defaultFieldValues: {
84 | autopause: false,
85 | autoplay: true,
86 | background: false,
87 | byline: false,
88 | controls: false,
89 | dnt: true,
90 | loop: true,
91 | muted: true,
92 | portrait: false,
93 | quality: "auto",
94 | title: false,
95 | // Load a reasonably large thumbnail up front. Note this will add
96 | // relevant width/height attributes to the iframe. If youre making
97 | // your player responsive on the frontend this will be ok, but keep
98 | // it in mind.
99 | width: "960"
100 | }
101 | },
102 | validation: Rule => Rule.required()
103 | },
104 | ],
105 | preview: {
106 | select: {
107 | vimeoVideo: "vimeoVideo"
108 | },
109 | prepare(selection) {
110 | let oEmbedData = selection.vimeoVideo
111 | ? selection.vimeoVideo.oEmbedData
112 | : {};
113 |
114 | return {
115 | title: oEmbedData.title || ""
116 | }
117 | }
118 | }
119 | };
120 | ```
121 |
122 | See: https://vimeo.com/475247026
123 |
124 | ## Additional Cases
125 |
126 | #### User Updates to Configuration
127 | > :warning: **Important**
128 |
129 | The user will be asked to reload the video any time they make changes to configurable fields. This is because configuration options are used during the _request_ to Vimeo for oEmbed data, and as such updated configurations require an updated request to Vimeo. The plugin will alert the user to this automatically.
130 |
131 | See: https://vimeo.com/475246939
132 |
133 | #### Non-Existent Vimeo URLs / Fail Case
134 | Should the user ever attempt to load a non-existent or errant Vimeo URL, the plugin will alert the user automatically.
135 |
136 | See: https://vimeo.com/475247012
137 |
138 | ## Configuration
139 |
140 | All configurable fields exposed through the `configurableFields` option match the configuration arguments available for use with [Vimeo's oEmbed API](https://developer.vimeo.com/api/oembed/videos). To expose a field for user configuration, simply add its name to the `configurableFields` array within the `options` object when adding the `vimeoVideo` type to your schema (see "Usage" section above). Further, each configurable field exposed to the user will include the description from the matching argument in Vimeo's API. To override any default value, use `defaultFieldValues` (see "Usage" section above).
141 |
142 | This is taken directly from Vimeo's documentation:
143 |
144 |
145 |
146 |
Argument
Default Value
Description
147 |
148 |
149 |
url
None
The URL of the video on Vimeo. This is a required value.
Whether to pause the current video when another Vimeo video on the same page starts to play.
152 |
autoplay
false
Whether to start playback of the video automatically. This feature might not work on all devices.
153 |
background
false
For videos on a Vimeo Plus account or higher: whether to hide all video controls, loop the video automatically, enable autoplay, and mute the video. The loop and autoplay behaviors can't be overridden, but the mute behavior can be; see the muted argument below.
154 |
byline
true
Whether to display the video owner's name.
155 |
callback
None
The name of JavaScript function to use as the callback parameter of a JSONP call. The indicated function wraps the JSON response.
156 |
controls
true
Whether to display (true) or hide (false) all interactive elements in the player interface. To start video playback when controls are hidden, set autoplay to true or use our player API. This argument is available only for Vimeo Pro and Business accounts.
157 |
color
None
The hexadecimal color value of the video controls, which is normally 00ADEF.
158 |
dnt
false
Whether to prevent the player from tracking session data, including cookies. Keep in mind that setting this argument to true also blocks video stats.
159 |
fun
true
Whether to disable informal error messages in the player, such as Oops.
160 |
height
None
The height of the video in pixels.
161 |
loop
false
Whether to restart the video automatically after reaching the end.
162 |
maxheight
None
The height of the video in pixels, where the video won't exceed its native height, no matter the value of this field.
163 |
maxwidth
None
The width of the video in pixels, where the video won't exceed its native width, no matter the value of this field.
164 |
muted
false
Whether to mute playback by default. The user can increase the volume manually.
165 |
player_id
None
The unique ID for the player, which comes back with all JavaScript API responses.
166 |
playsinline
true
Whether the video plays inline on supported mobile devices.
167 |
portrait
true
Whether to display the video owner's portrait.
168 |
quality
auto
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.
169 |
responsive
false
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.
170 |
speed
false
For videos on a Vimeo Plus account or higher: whether to include playback speed among the player preferences.
171 |
texttrack
None
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.
172 |
title
true
Whether to display the video's title.
173 |
transparent
true
Whether the background of the player area is transparent on Vimeo. When this value is false, the background of the player area is black. Depending on the video's aspect ratio, there might be visible black bars around the video.
42 | );
43 | };
44 |
45 | export default TextInput;
46 |
--------------------------------------------------------------------------------
/lib/components/VimeoInput/components/ConfigFieldsInput/constants.js:
--------------------------------------------------------------------------------
1 | export const CONFIGURATION_FIELD_TYPES = {
2 | BOOLEAN: "boolean",
3 | STRING: "string"
4 | };
5 |
6 | export const CONFIGURATION_FIELDS = [
7 | {
8 | argument: "api",
9 | default: true,
10 | description: "Whether to enable the Vimeo player SDK.",
11 | type: CONFIGURATION_FIELD_TYPES.BOOLEAN
12 | },
13 | {
14 | argument: "autopause",
15 | default: true,
16 | description: "Whether to pause the current video when another Vimeo video on the same page starts to play.",
17 | type: CONFIGURATION_FIELD_TYPES.BOOLEAN
18 | },
19 | {
20 | argument: "autoplay",
21 | default: false,
22 | description: "Whether to start playback of the video automatically. This feature might not work on all devices.",
23 | type: CONFIGURATION_FIELD_TYPES.BOOLEAN
24 | },
25 | {
26 | argument: "background",
27 | default: false,
28 | description: "For videos on a Vimeo Plus account or higher: whether to hide all video controls, loop the video automatically, enable autoplay, and mute the video. The loop and autoplay behaviors can't be overridden, but the mute behavior can be; see the muted argument below.",
29 | type: CONFIGURATION_FIELD_TYPES.BOOLEAN
30 | },
31 | {
32 | argument: "byline",
33 | default: true,
34 | description: "Whether to display the video owner's name.",
35 | type: CONFIGURATION_FIELD_TYPES.BOOLEAN
36 | },
37 | {
38 | argument: "callback",
39 | default: null,
40 | description: "The name of JavaScript function to use as the callback parameter of a JSONP call. The indicated function wraps the JSON response.",
41 | type: CONFIGURATION_FIELD_TYPES.STRING
42 | },
43 | {
44 | argument: "controls",
45 | default: true,
46 | description: "Whether to display (true) or hide (false) all interactive elements in the player interface. To start video playback when controls are hidden, set autoplay to true or use our player API. This argument is available only for Vimeo Pro and Business accounts.",
47 | type: CONFIGURATION_FIELD_TYPES.BOOLEAN
48 | },
49 | {
50 | argument: "color",
51 | default: null,
52 | description: "The hexadecimal color value of the video controls, which is normally 00ADEF.",
53 | type: CONFIGURATION_FIELD_TYPES.STRING
54 | },
55 | {
56 | argument: "dnt",
57 | default: false,
58 | description: "Whether to prevent the player from tracking session data, including cookies. Keep in mind that setting this argument to true also blocks video stats.",
59 | type: CONFIGURATION_FIELD_TYPES.BOOLEAN
60 | },
61 | {
62 | argument: "fun",
63 | default: true,
64 | description: "Whether to disable informal error messages in the player, such as Oops.",
65 | type: CONFIGURATION_FIELD_TYPES.BOOLEAN
66 | },
67 | {
68 | argument: "height",
69 | default: null,
70 | description: "The height of the video in pixels.",
71 | type: CONFIGURATION_FIELD_TYPES.STRING
72 | },
73 | {
74 | argument: "loop",
75 | default: false,
76 | description: "Whether to restart the video automatically after reaching the end.",
77 | type: CONFIGURATION_FIELD_TYPES.BOOLEAN
78 | },
79 | {
80 | argument: "maxheight",
81 | default: null,
82 | description: "The height of the video in pixels, where the video won't exceed its native height, no matter the value of this field.",
83 | type: CONFIGURATION_FIELD_TYPES.STRING
84 | },
85 | {
86 | argument: "maxwidth",
87 | default: null,
88 | description: "The width of the video in pixels, where the video won't exceed its native width, no matter the value of this field.",
89 | type: CONFIGURATION_FIELD_TYPES.STRING
90 | },
91 | {
92 | argument: "muted",
93 | default: false,
94 | description: "Whether to mute playback by default. The user can increase the volume manually.",
95 | type: CONFIGURATION_FIELD_TYPES.BOOLEAN
96 | },
97 | {
98 | argument: "player_id",
99 | default: null,
100 | description: "The unique ID for the player, which comes back with all JavaScript API responses.",
101 | type: CONFIGURATION_FIELD_TYPES.STRING
102 | },
103 | {
104 | argument: "playsinline",
105 | default: true,
106 | description: "Whether the video plays inline on supported mobile devices.",
107 | type: CONFIGURATION_FIELD_TYPES.BOOLEAN
108 | },
109 | {
110 | argument: "portrait",
111 | default: true,
112 | description: "Whether to display the video owner's portrait.",
113 | type: CONFIGURATION_FIELD_TYPES.BOOLEAN
114 | },
115 | {
116 | argument: "quality",
117 | default: "auto",
118 | description: "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.",
119 | type: CONFIGURATION_FIELD_TYPES.STRING
120 | },
121 | {
122 | argument: "responsive",
123 | default: false,
124 | description: "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.",
125 | type: CONFIGURATION_FIELD_TYPES.BOOLEAN
126 | },
127 | {
128 | argument: "speed",
129 | default: false,
130 | description: "For videos on a Vimeo Plus account or higher: whether to include playback speed among the player preferences.",
131 | type: CONFIGURATION_FIELD_TYPES.BOOLEAN
132 | },
133 | {
134 | argument: "texttrack",
135 | default: null,
136 | description: "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.",
137 | type: CONFIGURATION_FIELD_TYPES.STRING
138 | },
139 | {
140 | argument: "title",
141 | default: true,
142 | description: "Whether to display the video's title.",
143 | type: CONFIGURATION_FIELD_TYPES.BOOLEAN
144 | },
145 | {
146 | argument: "transparent",
147 | default: true,
148 | description: "Whether the background of the player area is transparent on Vimeo. When this value is false, the background of the player area is black. Depending on the video's aspect ratio, there might be visible black bars around the video.",
149 | type: CONFIGURATION_FIELD_TYPES.BOOLEAN
150 | },
151 | {
152 | argument: "width",
153 | default: null,
154 | description: "The width of the video in pixels.",
155 | type: CONFIGURATION_FIELD_TYPES.STRING
156 | },
157 | {
158 | argument: "xhtml",
159 | default: false,
160 | description: "Whether to make the embed code XHTML-compliant.",
161 | type: CONFIGURATION_FIELD_TYPES.BOOLEAN
162 | }
163 | ];
164 |
--------------------------------------------------------------------------------
/lib/components/VimeoInput/components/ConfigFieldsInput/index.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import Fieldset from "part:@sanity/components/fieldsets/default";
3 |
4 | import Switch from "./components/Switch";
5 | import TextInput from "./components/TextInput";
6 |
7 | import { CONFIGURATION_FIELD_TYPES, CONFIGURATION_FIELDS } from "./constants";
8 |
9 | const ConfigFieldsInput = (props, ref) => {
10 | const {
11 | configFields,
12 | disabled,
13 | defaultFieldValues,
14 | inputId,
15 | onFieldValueChange
16 | } = props;
17 |
18 | const renderedFields = Object.entries(configFields).map(([configFieldName, configFieldValue], i) => {
19 | const configFieldSettings = CONFIGURATION_FIELDS.find(configFieldSettings =>
20 | configFieldSettings.argument === configFieldName
21 | );
22 |
23 | if (!configFieldSettings) {
24 | console.error(
25 | `Could not locate a known configuration field for name ${ configFieldName }`
26 | );
27 | return null;
28 | }
29 |
30 | const fieldId = `${ inputId }__field-${ i }`;
31 |
32 | const fieldValue = configFieldValue == null
33 | ? (
34 | (configFieldName in defaultFieldValues)
35 | ? defaultFieldValues[configFieldName]
36 | : configFieldSettings.default
37 | )
38 | : configFieldValue;
39 |
40 | switch (configFieldSettings.type) {
41 | case CONFIGURATION_FIELD_TYPES.BOOLEAN:
42 | return (
43 | {
52 | onFieldValueChange({ field: configFieldName, value: value });
53 | }}
54 | />
55 | );
56 | break;
57 | case CONFIGURATION_FIELD_TYPES.STRING:
58 | return (
59 | {
67 | onFieldValueChange({ field: configFieldName, value: value });
68 | }}
69 | value={fieldValue}
70 | />
71 | );
72 | break;
73 | default:
74 | return null;
75 | }
76 | });
77 |
78 | if (renderedFields.length === 0) {
79 | return null;
80 | }
81 |
82 | return (
83 |
90 | );
91 | };
92 |
93 | export default ConfigFieldsInput;
94 |
--------------------------------------------------------------------------------
/lib/components/VimeoInput/components/Label/components/Description.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import formFieldStyles from "part:@sanity/components/formfields/default-style";
3 |
4 | const Description = props => {
5 | const { children } = props;
6 |
7 | return (
8 |
9 | { children }
10 |
11 | );
12 | };
13 |
14 | export default Description;
15 |
--------------------------------------------------------------------------------
/lib/components/VimeoInput/components/Label/components/Label.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import formFieldStyles from "part:@sanity/components/formfields/default-style";
3 |
4 | /* Label
5 | *
6 | * This component and its sub-components, Title and Description, essentially
7 | * mimic the current makeup of labels and descriptions for fields provided
8 | * within Sanity's `DefaultFormField`. However, due to a combination of Sanity
9 | * lacking better documentation for building complicated custom input components
10 | * and to Sanity's various existing components doing **magic** on the backend
11 | * in an attempt to hook some of its components into its own stores, it was
12 | * simply not an option to use the `DefaultFormField` in order to *just* get the
13 | * form field's label styling. Therefore, we had to cut it out ourselves. Enjoy!
14 | *
15 | * See: https://github.com/sanity-io/sanity/blob/next/packages/%40sanity/components/src/formfields/DefaultFormField.tsx
16 | */
17 | const Label = props => {
18 | const { children, htmlFor } = props;
19 |
20 | return (
21 |
28 | );
29 | };
30 |
31 | export default Label;
32 |
--------------------------------------------------------------------------------
/lib/components/VimeoInput/components/Label/components/Title.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import GenericSanityLabel from "part:@sanity/components/labels/default";
3 | import formFieldStyles from "part:@sanity/components/formfields/default-style";
4 |
5 | const Title = props => {
6 | const { children } = props;
7 |
8 | return (
9 |