PluginProbe ʕ •ᴥ•ʔ
Presto Player / 2.0.3
Presto Player v2.0.3
4.3.2 4.3.1 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 / placeholder.js
presto-player / src / admin / blocks / shared Last commit date
audioPresets 3 years ago branding 4 years ago chapters 2 years ago components 4 years ago media 3 years ago overlays 4 years ago presets 3 years ago services 4 years ago settings 4 years ago styles 2 years ago tracks 5 years ago BlockInspectorControls.js 4 years ago LinkPlaceholder.js 5 years ago Player.js 2 years ago Preview.js 3 years ago ProUpgradeModal.js 5 years ago VisibilityEditor.js 5 years ago audio-placeholder.js 4 years ago helpers.js 5 years ago options.js 5 years ago placeholder.js 5 years ago
placeholder.js
262 lines
1 /**
2 * External dependencies
3 */
4
5 const { noop } = lodash;
6 import classnames from "classnames";
7 const baseCurrentUrl = window.location.href;
8 import helpers from "./helpers";
9
10 /**
11 * WordPress dependencies
12 */
13 const {
14 Button,
15 Notice,
16 Placeholder,
17 DropZone,
18 withFilters,
19 BaseControl,
20 ToggleControl,
21 FormFileUpload,
22 } = wp.components;
23
24 const { __ } = wp.i18n;
25 const { useState, useEffect } = wp.element;
26 const { useSelect } = wp.data;
27 const deprecated = wp.deprecated;
28 const { MediaUpload, MediaUploadCheck, URLPopover } = wp.editor;
29 // const { URLPopover } = wp.blockEditor;
30
31 const InsertFromURLPopover = ({ src, onChange, onSubmit, onClose }) => (
32 <URLPopover onClose={onClose}>
33 <form
34 className="block-editor-media-placeholder__url-input-form"
35 onSubmit={onSubmit}
36 >
37 <input
38 data-cy="url-input"
39 className="block-editor-media-placeholder__url-input-field"
40 type="url"
41 aria-label={__("URL", "presto-player")}
42 placeholder={__(
43 "Paste or type a Youtube, Vimeo or .mp4 video URL",
44 "presto-player"
45 )}
46 onChange={onChange}
47 value={src}
48 />
49 <Button
50 data-cy="url-submit"
51 className="block-editor-media-placeholder__url-input-submit-button"
52 icon={"editor-break"}
53 label={__("Apply", "presto-player")}
54 type="submit"
55 />
56 </form>
57 </URLPopover>
58 );
59
60 export function MediaPlaceholder({
61 value = {},
62 allowedTypes = [],
63 className,
64 icon,
65 url = true,
66 labels = {},
67 mediaPreview,
68 notices,
69 isAppender,
70 isPrivate,
71 addToGallery,
72 onSelect,
73 onCancel,
74 onSelectURL,
75 onDoubleClick,
76 children,
77 allowURLs,
78 }) {
79 const mediaUpload = useSelect((select) => {
80 const { getSettings } = select("core/block-editor");
81 return getSettings().mediaUpload;
82 }, []);
83
84 const [src, setSrc] = useState("");
85 const [isURLInputVisible, setIsURLInputVisible] = useState(false);
86
87 useEffect(() => {
88 setSrc(value?.src ?? "");
89 }, [value]);
90
91 const onChangeSrc = (event) => {
92 setSrc(event.target.value);
93 };
94
95 const openURLInput = () => {
96 setIsURLInputVisible(true);
97 };
98
99 const closeURLInput = () => {
100 setIsURLInputVisible(false);
101 };
102
103 const onSubmitSrc = (event) => {
104 event.preventDefault();
105 if (src && onSelectURL) {
106 onSelectURL(src);
107 closeURLInput();
108 }
109 };
110
111 const renderPlaceholder = (content, onClick) => {
112 let { instructions, title } = labels;
113
114 if (!mediaUpload && !onSelectURL) {
115 instructions = __(
116 "To edit this block, you need permission to upload media.",
117 "presto-player"
118 );
119 }
120
121 // set class names
122 const placeholderClassName = classnames(
123 "block-editor-media-placeholder",
124 className,
125 {
126 "is-appender": isAppender,
127 }
128 );
129
130 return (
131 <Placeholder
132 icon={icon}
133 label={title}
134 instructions={instructions}
135 className={placeholderClassName}
136 notices={notices}
137 onClick={onClick}
138 onDoubleClick={onDoubleClick}
139 preview={mediaPreview}
140 >
141 {children}
142 {content}
143 </Placeholder>
144 );
145 };
146
147 const renderCancelLink = () => {
148 return (
149 onCancel && (
150 <Button
151 className="block-editor-media-placeholder__cancel-button"
152 title={__("Cancel", "presto-player")}
153 isLink
154 onClick={onCancel}
155 >
156 {__("Cancel", "presto-player")}
157 </Button>
158 )
159 );
160 };
161
162 const renderUrlSelectionUI = () => {
163 return (
164 onSelectURL && (
165 <div className="block-editor-media-placeholder__url-input-container">
166 {url && (
167 <Button
168 data-cy="video-url"
169 className="block-editor-media-placeholder__button"
170 onClick={openURLInput}
171 isPressed={isURLInputVisible}
172 isTertiary
173 >
174 {__("Video URL", "presto-player")}
175 </Button>
176 )}
177 {isURLInputVisible && (
178 <InsertFromURLPopover
179 src={src}
180 onChange={onChangeSrc}
181 onSubmit={onSubmitSrc}
182 onClose={closeURLInput}
183 />
184 )}
185 </div>
186 )
187 );
188 };
189
190 const renderMediaUploadChecked = () => {
191 const mediaLibraryButton = (
192 <MediaUpload
193 title={
194 isPrivate
195 ? __("Select or Upload Private Video", "presto-player")
196 : __("Select or Upload Video", "presto-player")
197 }
198 addToGallery={addToGallery}
199 gallery={false}
200 multiple={false}
201 onSelect={(event) => {
202 // set private/public url params
203 helpers.unsetUrlParams();
204 onSelect(event);
205 }}
206 onClose={() => {
207 // unset private/public url params
208 helpers.unsetUrlParams();
209 }}
210 allowedTypes={allowedTypes}
211 value={Array.isArray(value) ? value.map(({ id }) => id) : value.id}
212 render={({ open }) => {
213 return (
214 <Button
215 data-cy="add-video"
216 isPrimary
217 onClick={(event) => {
218 event.stopPropagation();
219 helpers.unsetUrlParams();
220 if (isPrivate) {
221 helpers.setUrlPrivate(baseCurrentUrl);
222 } else {
223 helpers.setUrlPublic(baseCurrentUrl);
224 }
225 open();
226 }}
227 >
228 {isPrivate
229 ? __("Add/Select Private Video", "presto-player")
230 : __("Add/Select Video", "presto-player")}
231 </Button>
232 );
233 }}
234 />
235 );
236
237 if (mediaUpload) {
238 const content = (
239 <>
240 {mediaLibraryButton}
241 {!!allowURLs && renderUrlSelectionUI()}
242 {renderCancelLink()}
243 </>
244 );
245 return renderPlaceholder(content);
246 }
247
248 return renderPlaceholder(mediaLibraryButton);
249 };
250
251 return (
252 <MediaUploadCheck fallback={renderPlaceholder(renderUrlSelectionUI())}>
253 {renderMediaUploadChecked()}
254 </MediaUploadCheck>
255 );
256 }
257
258 /**
259 * @see https://github.com/WordPress/gutenberg/blob/master/packages/block-editor/src/components/media-placeholder/README.md
260 */
261 export default withFilters("editor.MediaPlaceholder")(MediaPlaceholder);
262