PluginProbe ʕ •ᴥ•ʔ
Presto Player / trunk
Presto Player vtrunk
4.3.0 4.2.4 4.2.3 4.2.2 4.2.0 4.2.1 trunk 1.10.0 1.10.1 1.10.2 1.11.0 1.12.0 1.13.0 1.14.0 1.14.1 1.5.10 1.5.11 1.5.12 1.5.13 1.5.14 1.5.15 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.10 1.6.11 1.6.12 1.6.13 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.9.0 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.14 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.16 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.2.0 2.2.1 2.2.2 2.2.3 2.2.3-beta1 2.3.0 2.3.1 2.3.2 2.3.3 3.0.0 3.0.0-beta1 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.1.0 3.1.1 3.1.2 3.1.3 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4
presto-player / src / admin / blocks / shared / settings / index.js
presto-player / src / admin / blocks / shared / settings Last commit date
MutedPreviewOptions.js 6 months ago index.js 1 month ago settings-styles.css 5 years ago
index.js
300 lines
1 /**
2 * WordPress dependencies
3 */
4 import { __, sprintf } from "@wordpress/i18n";
5 const {
6 ToggleControl,
7 SelectControl,
8 BaseControl,
9 Button,
10 PanelRow,
11 Icon,
12 Flex,
13 } = wp.components;
14 const { dispatch } = wp.data;
15 import { isHLS } from "@/shared/util";
16
17 const { MediaUpload, MediaUploadCheck } = wp.blockEditor;
18 import ProBadge from "@/admin/blocks/shared/components/ProBadge";
19 import MutedPreviewOptions from "./MutedPreviewOptions";
20
21 const VIDEO_POSTER_ALLOWED_MEDIA_TYPES = ["image"];
22
23 const { useInstanceId } = wp.compose;
24
25 const VideoSettings = ({ setAttributes, attributes }) => {
26 const { mutedPreview, autoplay, playsInline, preload, poster, mutedOverlay } =
27 attributes;
28
29 const instanceId = useInstanceId(VideoSettings);
30
31 const videoPosterDescription = `video-block__poster-image-description-${instanceId}`;
32
33 const getAutoplayHelp = (checked) => {
34 return checked
35 ? __(
36 "Note: Autoplaying videos may cause usability issues for some visitors.",
37 "presto-player"
38 )
39 : null;
40 };
41
42 const posterRecommended = () => {
43 // if is hls and we've selected metadata or none, recommend a poster
44 if (
45 attributes?.src &&
46 isHLS(attributes?.src) &&
47 ["metadata", "none"].includes(preload)
48 ) {
49 return true;
50 }
51
52 return preload === "none" && !poster;
53 };
54
55 const toggleAttribute = (attribute) => {
56 return (newValue) => {
57 setAttributes({ [attribute]: newValue });
58 };
59 };
60
61 // handle poster select
62 function onSelectPoster(image) {
63 setAttributes({ poster: image.url });
64 }
65
66 function onRemovePoster() {
67 setAttributes({ poster: "" });
68 }
69
70 const mutedPreviewControls = () => {
71 return (
72 <>
73 <ToggleControl
74 label={
75 <>
76 {__("Muted Autoplay Preview", "presto-player")}{" "}
77 {!prestoPlayer?.isPremium && <ProBadge />}
78 </>
79 }
80 onChange={(value) => {
81 if (!prestoPlayer?.isPremium) {
82 dispatch("presto-player/player").setProModal(true);
83 return;
84 }
85 setAttributes({
86 mutedPreview: {
87 ...mutedPreview,
88 ...{ enabled: value },
89 },
90 });
91 }}
92 checked={mutedPreview?.enabled}
93 className="presto-setting__mutedPreview"
94 help={__("Shows a muted preview of the video.", "presto-player")}
95 />
96 {!!mutedPreview?.enabled && !attributes?.video_id && (
97 <PanelRow>
98 <ToggleControl
99 label={__("Muted Preview Captions", "presto-player")}
100 onChange={(value) => {
101 setAttributes({
102 mutedPreview: {
103 ...mutedPreview,
104 ...{ captions: value },
105 },
106 });
107 }}
108 checked={mutedPreview?.captions}
109 className="presto-setting__mutedPreviewCaptions"
110 help={__("Play captions during muted autoplay", "presto-player")}
111 />
112 </PanelRow>
113 )}
114
115 {!!mutedPreview.enabled && (
116 <PanelRow>
117 <ToggleControl
118 label={
119 <>
120 {__("Muted Preview Overlay", "presto-player")}{" "}
121 {!prestoPlayer?.isPremium && <ProBadge />}
122 </>
123 }
124 onChange={(value) => {
125 if (!prestoPlayer?.isPremium) {
126 dispatch("presto-player/player").setProModal(true);
127 return;
128 }
129 setAttributes({
130 mutedOverlay: {
131 ...mutedOverlay,
132 ...{ enabled: value },
133 },
134 });
135 }}
136 checked={mutedOverlay?.enabled}
137 className="presto-setting__mutedOverlay"
138 help={__(
139 "Show an image over the top of the video either before or after the video.",
140 "presto-player"
141 )}
142 />
143 </PanelRow>
144 )}
145 {mutedOverlay?.enabled && mutedPreview?.enabled && (
146 <MutedPreviewOptions
147 attributes={attributes}
148 setAttributes={setAttributes}
149 />
150 )}
151 </>
152 );
153 };
154
155 return (
156 <>
157 {!autoplay && mutedPreviewControls()}
158
159 {!mutedPreview?.enabled && (
160 <ToggleControl
161 label={__("Autoplay", "presto-player")}
162 className="presto-setting__autoplay"
163 onChange={toggleAttribute("autoplay")}
164 checked={autoplay}
165 help={getAutoplayHelp}
166 />
167 )}
168 <PanelRow>
169 <ToggleControl
170 label={__("Play inline", "presto-player")}
171 className="presto-setting__playsInline"
172 data-cy={"playsInline"}
173 onChange={toggleAttribute("playsInline")}
174 checked={playsInline}
175 help={__(
176 "On mobile browsers, play the video on the page instead of opening it up fullscreen.",
177 "presto-player"
178 )}
179 />
180 </PanelRow>
181 {!attributes?.video_id && (
182 <PanelRow>
183 <SelectControl
184 label={
185 <Flex justify="flex-start" align="center" gap={1}>
186 <div style={{ whiteSpace: "nowrap" }}>
187 {__("Performance Preference", "presto-player")}
188 </div>
189 <a
190 href="https://prestoplayer.com/docs/performance-preferences-explained"
191 target="_blank"
192 style={{ textDecoration: "none" }}
193 >
194 <Icon icon="editor-help" />
195 </a>
196 </Flex>
197 }
198 className="presto-setting__preload"
199 value={preload}
200 onChange={(value) => setAttributes({ preload: value })}
201 help={
202 posterRecommended() &&
203 __(
204 "A poster image is recommended for this setting.",
205 "presto-player"
206 )
207 }
208 options={[
209 {
210 value: "auto",
211 label: __("Video Playback Speed", "presto-player"),
212 },
213 {
214 value: "metadata",
215 label: __("Page Load Speed", "presto-player"),
216 },
217 {
218 value: "none",
219 label: __("Page Load Speed (Extreme)", "presto-player"),
220 },
221 ]}
222 />
223 </PanelRow>
224 )}
225 <PanelRow>
226 <MediaUploadCheck>
227 <BaseControl className="editor-video-poster-control">
228 <BaseControl.VisualLabel>
229 {__("Poster image", "presto-player")}
230 </BaseControl.VisualLabel>
231 <MediaUpload
232 title={__("Select poster image", "presto-player")}
233 onSelect={onSelectPoster}
234 allowedTypes={VIDEO_POSTER_ALLOWED_MEDIA_TYPES}
235 render={({ open }) => (
236 <Button
237 className="presto-setting__poster"
238 isPrimary
239 onClick={open}
240 aria-describedby={videoPosterDescription}
241 >
242 {!poster
243 ? __("Select", "presto-player")
244 : __("Replace", "presto-player")}
245 </Button>
246 )}
247 />
248 <p id={videoPosterDescription} hidden>
249 {poster
250 ? sprintf(
251 __("The current poster image url is %s", "presto-player"),
252 poster
253 )
254 : __(
255 "There is no poster image currently selected",
256 "presto-player"
257 )}
258 </p>
259 {!!poster && (
260 <Button
261 onClick={onRemovePoster}
262 className="presto-setting__remove-poster"
263 isTertiary
264 >
265 {__("Remove", "presto-player")}
266 </Button>
267 )}
268 </BaseControl>
269 </MediaUploadCheck>
270 </PanelRow>
271 <PanelRow>
272 <div style={{ width: "100%", flex: 1 }}>
273 <SelectControl
274 label={__("Aspect Ratio", "presto-player")}
275 value={attributes?.ratio}
276 onChange={(value) => {
277 setAttributes({ ratio: value });
278 }}
279 options={[
280 { value: "original", label: __("Original", "presto-player") },
281 { value: "1:1", label: __("Square - 1:1", "presto-player") },
282 { value: "4:3", label: __("Standard - 4:3", "presto-player") },
283 { value: "3:4", label: __("Portrait - 3:4", "presto-player") },
284 { value: "3:2", label: __("Classic - 3:2", "presto-player") },
285 {
286 value: "2:3",
287 label: __("Classic Portrait - 2:3", "presto-player"),
288 },
289 { value: "16:9", label: __("Wide - 16:9", "presto-player") },
290 { value: "9:16", label: __("Tall - 9:16", "presto-player") },
291 ]}
292 />
293 </div>
294 </PanelRow>
295 </>
296 );
297 };
298
299 export default VideoSettings;
300