| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
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 unregisterConnector(slug) { 96 return { 97 type: "UNREGISTER_CONNECTOR", 98 slug 99 }; 100 } 101 }; 102 function reducer(state = DEFAULT_STATE, action) { 103 switch (action.type) { 104 case "REGISTER_CONNECTOR": 105 return { 106 ...state, 107 connectors: { 108 ...state.connectors, 109 [action.slug]: { 110 ...state.connectors[action.slug], 111 slug: action.slug, 112 ...action.config 113 } 114 } 115 }; 116 case "UNREGISTER_CONNECTOR": { 117 if (!state.connectors[action.slug]) { 118 return state; 119 } 120 const { [action.slug]: _, ...rest } = state.connectors; 121 return { 122 ...state, 123 connectors: rest 124 }; 125 } 126 default: 127 return state; 128 } 129 } 130 var selectors = { 131 getConnectors: (0, import_data.createSelector)( 132 (state) => Object.values(state.connectors), 133 (state) => [state.connectors] 134 ), 135 getConnector(state, slug) { 136 return state.connectors[slug]; 137 } 138 }; 139 var store = (0, import_data.createReduxStore)(STORE_NAME, { 140 reducer 141 }); 142 (0, import_data.register)(store); 143 unlock(store).registerPrivateActions(actions); 144 unlock(store).registerPrivateSelectors(selectors); 145 146 // packages/connectors/build-module/api.mjs 147 function registerConnector(slug, config) { 148 unlock((0, import_data2.dispatch)(store)).registerConnector(slug, config); 149 } 150 function unregisterConnector(slug) { 151 unlock((0, import_data2.dispatch)(store)).unregisterConnector(slug); 152 } 153 154 // packages/connectors/build-module/connector-item.mjs 155 var import_components = __toESM(require_components(), 1); 156 var import_element = __toESM(require_element(), 1); 157 var import_i18n = __toESM(require_i18n(), 1); 158 var import_jsx_runtime = __toESM(require_jsx_runtime(), 1); 159 function ConnectorItem({ 160 className, 161 logo, 162 name, 163 description, 164 actionArea, 165 children 166 }) { 167 const headingId = (0, import_element.useId)(); 168 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.__experimentalItem, { className, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalVStack, { spacing: 4, role: "group", "aria-labelledby": headingId, children: [ 169 /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalHStack, { alignment: "center", spacing: 4, wrap: true, children: [ 170 logo, 171 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.FlexBlock, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalVStack, { spacing: 0, children: [ 172 /* @__PURE__ */ (0, import_jsx_runtime.jsx)( 173 import_components.__experimentalText, 174 { 175 weight: 600, 176 size: 15, 177 id: headingId, 178 as: "h2", 179 children: name 180 } 181 ), 182 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.__experimentalText, { variant: "muted", size: 12, children: description }) 183 ] }) }), 184 actionArea 185 ] }), 186 children 187 ] }) }); 188 } 189 function DefaultConnectorSettings({ 190 onSave, 191 onRemove, 192 initialValue = "", 193 helpUrl, 194 helpLabel, 195 readOnly = false, 196 keySource 197 }) { 198 const [apiKey, setApiKey] = (0, import_element.useState)(initialValue); 199 const [isSaving, setIsSaving] = (0, import_element.useState)(false); 200 const [saveError, setSaveError] = (0, import_element.useState)(null); 201 const helpLinkLabel = helpLabel || helpUrl?.replace(/^https?:\/\//, ""); 202 const helpLink = helpUrl ? (0, import_element.createInterpolateElement)( 203 (0, import_i18n.sprintf)( 204 /* translators: %s: Link to provider settings. */ 205 (0, import_i18n.__)("Get your API key at %s"), 206 "<a></a>" 207 ), 208 { 209 a: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.ExternalLink, { href: helpUrl, children: helpLinkLabel }) 210 } 211 ) : void 0; 212 const isExternallyConfigured = keySource === "env" || keySource === "constant"; 213 const getHelp = () => { 214 if (isExternallyConfigured) { 215 if (keySource === "env") { 216 return (0, import_i18n.__)( 217 "This API key is configured using an environment variable." 218 ); 219 } 220 if (keySource === "constant") { 221 return (0, import_i18n.__)("This API key is configured as a constant."); 222 } 223 } 224 if (readOnly) { 225 return helpUrl ? (0, import_element.createInterpolateElement)( 226 (0, import_i18n.sprintf)( 227 /* translators: %s: Link to provider settings. */ 228 (0, import_i18n.__)( 229 "Your API key is stored securely. You can manage it at %s" 230 ), 231 "<a></a>" 232 ), 233 { 234 a: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.ExternalLink, { href: helpUrl, children: helpLinkLabel }) 235 } 236 ) : (0, import_i18n.__)("Your API key is stored securely."); 237 } 238 if (saveError) { 239 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { role: "alert", className: "connector-settings__error", children: saveError }); 240 } 241 return helpLink; 242 }; 243 const handleSave = async () => { 244 setSaveError(null); 245 setIsSaving(true); 246 try { 247 await onSave?.(apiKey); 248 } catch (error) { 249 setSaveError( 250 error instanceof Error ? error.message : (0, import_i18n.__)( 251 "It was not possible to connect to the provider using this key." 252 ) 253 ); 254 } finally { 255 setIsSaving(false); 256 } 257 }; 258 return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)( 259 import_components.__experimentalVStack, 260 { 261 spacing: 4, 262 className: "connector-settings", 263 style: readOnly ? { 264 "--wp-components-color-background": "#f0f0f0" 265 } : void 0, 266 children: [ 267 /* @__PURE__ */ (0, import_jsx_runtime.jsx)( 268 import_components.TextControl, 269 { 270 __next40pxDefaultSize: true, 271 label: (0, import_i18n.__)("API Key"), 272 value: apiKey, 273 onChange: (value) => { 274 if (!readOnly) { 275 setSaveError(null); 276 setApiKey(value); 277 } 278 }, 279 placeholder: (0, import_i18n.__)("Enter your API key"), 280 disabled: readOnly || isSaving, 281 help: getHelp() 282 } 283 ), 284 readOnly ? onRemove && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.__experimentalHStack, { justify: "flex-start", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)( 285 import_components.Button, 286 { 287 variant: "link", 288 isDestructive: true, 289 onClick: onRemove, 290 children: (0, import_i18n.__)("Remove and replace") 291 } 292 ) }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.__experimentalHStack, { justify: "flex-start", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)( 293 import_components.Button, 294 { 295 __next40pxDefaultSize: true, 296 variant: "primary", 297 disabled: !apiKey || isSaving, 298 accessibleWhenDisabled: true, 299 isBusy: isSaving, 300 onClick: handleSave, 301 children: (0, import_i18n.__)("Save") 302 } 303 ) }) 304 ] 305 } 306 ); 307 } 308 309 // packages/connectors/build-module/private-apis.mjs 310 var privateApis = {}; 311 lock(privateApis, { store, STORE_NAME }); 312 export { 313 ConnectorItem as __experimentalConnectorItem, 314 DefaultConnectorSettings as __experimentalDefaultConnectorSettings, 315 registerConnector as __experimentalRegisterConnector, 316 unregisterConnector as __experimentalUnregisterConnector, 317 privateApis 318 };
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Sat Jun 13 09:38:55 2026 | Cross-referenced by PHPXref |