PluginProbe
Gutenberg / 22.7.0
Gutenberg v22.7.0
24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 All 403 releases
gutenberg / build / modules / connectors / index.js

index.js in Gutenberg 22.7.0, at build/modules/connectors/index.js

269 lines 9.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 var __create = Object.create;
2 var __defProp = Object.defineProperty;
3 var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4 var __getOwnPropNames = Object.getOwnPropertyNames;
5 var __getProtoOf = Object.getPrototypeOf;
6 var __hasOwnProp = Object.prototype.hasOwnProperty;
7 var __commonJS = (cb, mod) => function __require() {
8 return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9 };
10 var __copyProps = (to, from, except, desc) => {
11 if (from && typeof from === "object" || typeof from === "function") {
12 for (let key of __getOwnPropNames(from))
13 if (!__hasOwnProp.call(to, key) && key !== except)
14 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15 }
16 return to;
17 };
18 var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19 // If the importer is in node compatibility mode or this is not an ESM
20 // file that has been converted to a CommonJS file using a Babel-
21 // compatible transform (i.e. "__esModule" has not been set), then set
22 // "default" to the CommonJS "module.exports" for node compatibility.
23 isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24 mod
25 ));
26
27 // package-external:@wordpress/data
28 var require_data = __commonJS({
29 "package-external:@wordpress/data"(exports, module) {
30 module.exports = window.wp.data;
31 }
32 });
33
34 // package-external:@wordpress/private-apis
35 var require_private_apis = __commonJS({
36 "package-external:@wordpress/private-apis"(exports, module) {
37 module.exports = window.wp.privateApis;
38 }
39 });
40
41 // package-external:@wordpress/components
42 var require_components = __commonJS({
43 "package-external:@wordpress/components"(exports, module) {
44 module.exports = window.wp.components;
45 }
46 });
47
48 // package-external:@wordpress/element
49 var require_element = __commonJS({
50 "package-external:@wordpress/element"(exports, module) {
51 module.exports = window.wp.element;
52 }
53 });
54
55 // package-external:@wordpress/i18n
56 var require_i18n = __commonJS({
57 "package-external:@wordpress/i18n"(exports, module) {
58 module.exports = window.wp.i18n;
59 }
60 });
61
62 // vendor-external:react/jsx-runtime
63 var require_jsx_runtime = __commonJS({
64 "vendor-external:react/jsx-runtime"(exports, module) {
65 module.exports = window.ReactJSXRuntime;
66 }
67 });
68
69 // packages/connectors/build-module/api.mjs
70 var import_data2 = __toESM(require_data(), 1);
71
72 // packages/connectors/build-module/store.mjs
73 var import_data = __toESM(require_data(), 1);
74
75 // packages/connectors/build-module/lock-unlock.mjs
76 var import_private_apis = __toESM(require_private_apis(), 1);
77 var { lock, unlock } = (0, import_private_apis.__dangerousOptInToUnstableAPIsOnlyForCoreModules)(
78 "I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.",
79 "@wordpress/connectors"
80 );
81
82 // packages/connectors/build-module/store.mjs
83 var STORE_NAME = "core/connectors";
84 var DEFAULT_STATE = {
85 connectors: {}
86 };
87 var actions = {
88 registerConnector(slug, config) {
89 return {
90 type: "REGISTER_CONNECTOR",
91 slug,
92 config
93 };
94 }
95 };
96 function reducer(state = DEFAULT_STATE, action) {
97 switch (action.type) {
98 case "REGISTER_CONNECTOR":
99 return {
100 ...state,
101 connectors: {
102 ...state.connectors,
103 [action.slug]: {
104 slug: action.slug,
105 ...action.config
106 }
107 }
108 };
109 default:
110 return state;
111 }
112 }
113 var selectors = {
114 getConnectors(state) {
115 return Object.values(state.connectors);
116 },
117 getConnector(state, slug) {
118 return state.connectors[slug];
119 }
120 };
121 var store = (0, import_data.createReduxStore)(STORE_NAME, {
122 reducer
123 });
124 (0, import_data.register)(store);
125 unlock(store).registerPrivateActions(actions);
126 unlock(store).registerPrivateSelectors(selectors);
127
128 // packages/connectors/build-module/api.mjs
129 function registerConnector(slug, config) {
130 unlock((0, import_data2.dispatch)(store)).registerConnector(slug, config);
131 }
132
133 // packages/connectors/build-module/connector-item.mjs
134 var import_components = __toESM(require_components(), 1);
135 var import_element = __toESM(require_element(), 1);
136 var import_i18n = __toESM(require_i18n(), 1);
137 var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
138 function ConnectorItem({
139 className,
140 icon,
141 name,
142 description,
143 actionArea,
144 children
145 }) {
146 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.__experimentalItem, { className, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalVStack, { spacing: 4, children: [
147 /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalHStack, { alignment: "center", spacing: 4, children: [
148 icon,
149 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.FlexBlock, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalVStack, { spacing: 0, children: [
150 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.__experimentalText, { weight: 600, size: 15, children: name }),
151 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.__experimentalText, { variant: "muted", size: 12, children: description })
152 ] }) }),
153 actionArea
154 ] }),
155 children
156 ] }) });
157 }
158 function DefaultConnectorSettings({
159 onSave,
160 onRemove,
161 initialValue = "",
162 helpUrl,
163 helpLabel,
164 readOnly = false
165 }) {
166 const [apiKey, setApiKey] = (0, import_element.useState)(initialValue);
167 const [isSaving, setIsSaving] = (0, import_element.useState)(false);
168 const [saveError, setSaveError] = (0, import_element.useState)(null);
169 const helpLinkLabel = helpLabel || helpUrl?.replace(/^https?:\/\//, "");
170 const helpLink = helpUrl ? (0, import_element.createInterpolateElement)(
171 (0, import_i18n.sprintf)(
172 /* translators: %s: Link to provider settings. */
173 (0, import_i18n.__)("Get your API key at %s"),
174 "<a></a>"
175 ),
176 {
177 a: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.ExternalLink, { href: helpUrl, children: helpLinkLabel })
178 }
179 ) : void 0;
180 const getHelp = () => {
181 if (readOnly) {
182 return helpUrl ? (0, import_element.createInterpolateElement)(
183 (0, import_i18n.sprintf)(
184 /* translators: %s: Link to provider settings. */
185 (0, import_i18n.__)(
186 "Your API key is stored securely. You can reset it at %s"
187 ),
188 "<a></a>"
189 ),
190 {
191 a: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.ExternalLink, { href: helpUrl, children: helpLinkLabel })
192 }
193 ) : (0, import_i18n.__)("Your API key is stored securely.");
194 }
195 if (saveError) {
196 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { color: "#cc1818" }, children: saveError });
197 }
198 return helpLink;
199 };
200 const handleSave = async () => {
201 setSaveError(null);
202 setIsSaving(true);
203 try {
204 await onSave?.(apiKey);
205 } catch (error) {
206 setSaveError(
207 error instanceof Error ? error.message : (0, import_i18n.__)(
208 "It was not possible to connect to the provider using this key."
209 )
210 );
211 } finally {
212 setIsSaving(false);
213 }
214 };
215 return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
216 import_components.__experimentalVStack,
217 {
218 spacing: 4,
219 className: "connector-settings",
220 style: readOnly ? {
221 "--wp-components-color-background": "#f0f0f0"
222 } : void 0,
223 children: [
224 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
225 import_components.TextControl,
226 {
227 __nextHasNoMarginBottom: true,
228 __next40pxDefaultSize: true,
229 label: (0, import_i18n.__)("API Key"),
230 value: apiKey,
231 onChange: (value) => {
232 if (!readOnly) {
233 setSaveError(null);
234 setApiKey(value);
235 }
236 },
237 placeholder: "YOUR_API_KEY",
238 disabled: readOnly || isSaving,
239 help: getHelp()
240 }
241 ),
242 readOnly ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Button, { variant: "link", isDestructive: true, onClick: onRemove, children: (0, import_i18n.__)("Remove and replace") }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.__experimentalHStack, { justify: "flex-start", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
243 import_components.Button,
244 {
245 __next40pxDefaultSize: true,
246 variant: "primary",
247 disabled: !apiKey || isSaving,
248 accessibleWhenDisabled: true,
249 isBusy: isSaving,
250 onClick: handleSave,
251 children: (0, import_i18n.__)("Save")
252 }
253 ) })
254 ]
255 }
256 );
257 }
258
259 // packages/connectors/build-module/private-apis.mjs
260 var privateApis = {};
261 lock(privateApis, { store, STORE_NAME });
262 export {
263 ConnectorItem as __experimentalConnectorItem,
264 DefaultConnectorSettings as __experimentalDefaultConnectorSettings,
265 registerConnector as __experimentalRegisterConnector,
266 privateApis
267 };
268 //# sourceMappingURL=index.js.map
269