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