PluginProbe ʕ •ᴥ•ʔ
Presto Player / 4.3.1
Presto Player v4.3.1
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 / components / UrlSelect.js
presto-player / src / admin / blocks / shared / components Last commit date
ColorPopup.js 2 weeks ago ColorPopup.scss 2 weeks ago EntitySearchDropdown.js 2 weeks ago EntitySearchDropdown.scss 2 weeks ago LoadSelect.js 5 years ago ProBadge.js 5 years ago SelectMediaDropdown.js 2 weeks ago SelectMediaDropdown.scss 2 weeks ago Tag.js 2 weeks ago Tag.scss 2 weeks ago TranscriptionLanguageSelect.js 2 weeks ago UrlSelect.js 2 weeks ago UrlSelect.scss 2 weeks ago VideoIcon.js 2 weeks ago VideoIcon.scss 2 weeks ago
UrlSelect.js
129 lines
1 const { __ } = wp.i18n;
2 const { Button, Popover, Icon } = wp.components;
3
4 const { __experimentalLinkControl: LinkControl } = wp.blockEditor;
5 const { useState } = wp.element;
6 const { prependHTTP } = wp.url;
7
8 import "./UrlSelect.scss";
9
10 export default ({ setSettings, settings }) => {
11 const [visible, setVisible] = useState(false);
12 const { url } = settings;
13
14 /**
15 * Pending settings to be applied to the next link. When inserting a new
16 * link, toggle values cannot be applied immediately, because there is not
17 * yet a link for them to apply to. Thus, they are maintained in a state
18 * value until the time that the link can be inserted or edited.
19 *
20 * @type {[Object|undefined,Function]}
21 */
22 const [nextLinkValue, setNextLinkValue] = useState();
23
24 const linkValue = {
25 url: settings?.url,
26 type: settings?.type,
27 id: settings?.id,
28 opensInNewTab: settings?.opensInNewTab,
29 ...nextLinkValue,
30 };
31
32 const onChangeLink = (nextValue) => {
33 // Merge with values from state, both for the purpose of assigning the
34 // next state value, and for use in constructing the new link format if
35 // the link is ready to be applied.
36 nextValue = {
37 ...nextLinkValue,
38 ...nextValue,
39 };
40
41 // LinkControl calls `onChange` immediately upon the toggling a setting.
42 const didToggleSetting =
43 linkValue.opensInNewTab !== nextValue.opensInNewTab &&
44 linkValue.url === nextValue.url;
45
46 // If change handler was called as a result of a settings change during
47 // link insertion, it must be held in state until the link is ready to
48 // be applied.
49 const didToggleSettingForNewLink =
50 didToggleSetting && nextValue.url === undefined;
51
52 // If link will be assigned, the state value can be considered flushed.
53 // Otherwise, persist the pending changes.
54 setNextLinkValue(didToggleSettingForNewLink ? nextValue : undefined);
55
56 if (didToggleSettingForNewLink) {
57 return;
58 }
59
60 const newUrl = prependHTTP(nextValue.url);
61 setSettings({
62 url: newUrl,
63 type: nextValue.type,
64 id:
65 nextValue.id !== undefined && nextValue.id !== null
66 ? String(nextValue.id)
67 : undefined,
68 opensInNewTab: nextValue.opensInNewTab,
69 });
70 };
71
72 const confirmTrash = () => {
73 const r = confirm(
74 __("Are you sure you wish to remove this link?", "presto-player")
75 );
76 if (r) {
77 setSettings({});
78 }
79 };
80
81 return (
82 <span>
83 {url ? (
84 <div className="presto-url-select__display">
85 <div className="presto-url-select__url-container">
86 <a
87 href="#"
88 className="presto-url-select__link"
89 onClick={() => setVisible(!visible)}
90 >
91 <Icon
92 icon="edit"
93 className="presto-url-select__edit-icon"
94 />
95 {url}
96 </a>
97 {visible && (
98 <Popover
99 position="bottom center"
100 onClose={() => setVisible(false)}
101 >
102 <LinkControl value={settings} onChange={onChangeLink} />
103 </Popover>
104 )}
105 </div>
106 <div className="presto-url-select__actions">
107 <Icon
108 onClick={confirmTrash}
109 icon="trash"
110 className="presto-url-select__trash-icon"
111 />
112 </div>
113 </div>
114 ) : (
115 <span>
116 <Button isPrimary isSmall onClick={() => setVisible(!visible)}>
117 {__("Add Link", "presto-player")}
118 </Button>
119 {visible && (
120 <Popover className="presto-url-select__popover" position="bottom right" onClose={() => setVisible(false)}>
121 <LinkControl value={settings} onChange={onChangeLink} />
122 </Popover>
123 )}
124 </span>
125 )}
126 </span>
127 );
128 };
129