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