PluginProbe ʕ •ᴥ•ʔ
Presto Player / 2.2.2
Presto Player v2.2.2
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 years ago LoadSelect.js 5 years ago ProBadge.js 5 years ago UrlSelect.js 2 years ago
UrlSelect.js
178 lines
1 /** @jsx jsx */
2 const { __ } = wp.i18n;
3 const { Button, Popover, Icon } = wp.components;
4
5 const { __experimentalLinkControl: LinkControl } = wp.blockEditor;
6 const { useState } = wp.element;
7 const { prependHTTP } = wp.url;
8
9 import { css, jsx } from "@emotion/core";
10
11 export default ({ setSettings, settings }) => {
12 const [visible, setVisible] = useState(false);
13 const { url } = settings;
14
15 /**
16 * Pending settings to be applied to the next link. When inserting a new
17 * link, toggle values cannot be applied immediately, because there is not
18 * yet a link for them to apply to. Thus, they are maintained in a state
19 * value until the time that the link can be inserted or edited.
20 *
21 * @type {[Object|undefined,Function]}
22 */
23 const [nextLinkValue, setNextLinkValue] = useState();
24
25 const linkValue = {
26 url: settings?.url,
27 type: settings?.type,
28 id: settings?.id,
29 opensInNewTab: settings?.opensInNewTab,
30 ...nextLinkValue,
31 };
32
33 const onChangeLink = (nextValue) => {
34 // Merge with values from state, both for the purpose of assigning the
35 // next state value, and for use in constructing the new link format if
36 // the link is ready to be applied.
37 nextValue = {
38 ...nextLinkValue,
39 ...nextValue,
40 };
41
42 // LinkControl calls `onChange` immediately upon the toggling a setting.
43 const didToggleSetting =
44 linkValue.opensInNewTab !== nextValue.opensInNewTab &&
45 linkValue.url === nextValue.url;
46
47 // If change handler was called as a result of a settings change during
48 // link insertion, it must be held in state until the link is ready to
49 // be applied.
50 const didToggleSettingForNewLink =
51 didToggleSetting && nextValue.url === undefined;
52
53 // If link will be assigned, the state value can be considered flushed.
54 // Otherwise, persist the pending changes.
55 setNextLinkValue(didToggleSettingForNewLink ? nextValue : undefined);
56
57 if (didToggleSettingForNewLink) {
58 return;
59 }
60
61 const newUrl = prependHTTP(nextValue.url);
62 setSettings({
63 url: newUrl,
64 type: nextValue.type,
65 id:
66 nextValue.id !== undefined && nextValue.id !== null
67 ? String(nextValue.id)
68 : undefined,
69 opensInNewTab: nextValue.opensInNewTab,
70 });
71 };
72
73 const confirmTrash = () => {
74 const r = confirm(
75 __("Are you sure you wish to remove this link?", "presto-player")
76 );
77 if (r) {
78 setSettings({});
79 }
80 };
81
82 return (
83 <span>
84 {url ? (
85 <div
86 css={css`
87 display: flex;
88 justify-content: space-between;
89 `}
90 >
91 <div
92 css={css`
93 max-width: 85%;
94 overflow: hidden;
95 display: flex;
96 align-items: center;
97 `}
98 >
99 <a
100 href="#"
101 css={css`
102 padding: 10px;
103 background: #f3f3f3;
104 border-radius: 4px;
105 width: 100%;
106 display: inline-flex;
107 align-items: center;
108 white-space: nowrap;
109 overflow: hidden;
110 text-overflow: ellipsis;
111 text-decoration: none;
112 `}
113 onClick={() => setVisible(!visible)}
114 >
115 <Icon
116 icon="edit"
117 css={css`
118 cursor: pointer;
119 opacity: 0.75;
120 margin: 0 2px;
121 font-size: 16px;
122 width: 16px;
123 height: 16px;
124 text-decoration: none;
125 `}
126 />
127 {url}
128 </a>
129 {visible && (
130 <Popover
131 position="bottom center"
132 onClose={() => setVisible(false)}
133 >
134 <LinkControl value={settings} onChange={onChangeLink} />
135 </Popover>
136 )}
137 </div>
138 <div
139 css={css`
140 display: flex;
141 align-items: center;
142 `}
143 >
144 <Icon
145 onClick={confirmTrash}
146 icon="trash"
147 className="presto-icon"
148 css={css`
149 cursor: pointer;
150 opacity: 0.75;
151 margin: 0 2px;
152 fontsize: 18px;
153 width: 18px;
154 height: 18px;
155
156 &:hover {
157 color: #cc1818;
158 }
159 `}
160 />
161 </div>
162 </div>
163 ) : (
164 <span>
165 <Button isPrimary isSmall onClick={() => setVisible(!visible)}>
166 {__("Add Link", "presto-player")}
167 </Button>
168 {visible && (
169 <Popover css={css`margin-top: 10px`} position="bottom right" onClose={() => setVisible(false)}>
170 <LinkControl value={settings} onChange={onChangeLink} />
171 </Popover>
172 )}
173 </span>
174 )}
175 </span>
176 );
177 };
178