| 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: "var(--wpds-typography-font-weight-emphasis, 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 getHelpLinkLabel(helpUrl, helpLabel) { |
| 190 |
if (helpLabel) { |
| 191 |
return helpLabel; |
| 192 |
} |
| 193 |
if (!helpUrl) { |
| 194 |
return void 0; |
| 195 |
} |
| 196 |
try { |
| 197 |
return new URL(helpUrl).hostname; |
| 198 |
} catch { |
| 199 |
return helpUrl; |
| 200 |
} |
| 201 |
} |
| 202 |
function createConnectorHelpLink(helpUrl, helpLabel, message) { |
| 203 |
if (!helpUrl) { |
| 204 |
return void 0; |
| 205 |
} |
| 206 |
return (0, import_element.createInterpolateElement)( |
| 207 |
(0, import_i18n.sprintf)(message, "<a></a>"), |
| 208 |
{ |
| 209 |
a: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.ExternalLink, { href: helpUrl, children: getHelpLinkLabel(helpUrl, helpLabel) }) |
| 210 |
} |
| 211 |
); |
| 212 |
} |
| 213 |
function useConnectorSettingsSave(onSave, fallbackErrorMessage) { |
| 214 |
const [isSaving, setIsSaving] = (0, import_element.useState)(false); |
| 215 |
const [saveError, setSaveError] = (0, import_element.useState)(null); |
| 216 |
const handleSave = async (value) => { |
| 217 |
setSaveError(null); |
| 218 |
setIsSaving(true); |
| 219 |
try { |
| 220 |
await onSave?.(value); |
| 221 |
} catch (error) { |
| 222 |
setSaveError( |
| 223 |
error instanceof Error ? error.message : fallbackErrorMessage |
| 224 |
); |
| 225 |
} finally { |
| 226 |
setIsSaving(false); |
| 227 |
} |
| 228 |
}; |
| 229 |
return { |
| 230 |
isSaving, |
| 231 |
saveError, |
| 232 |
setSaveError, |
| 233 |
handleSave |
| 234 |
}; |
| 235 |
} |
| 236 |
function ConnectorSettingsFrame({ |
| 237 |
readOnly, |
| 238 |
children |
| 239 |
}) { |
| 240 |
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)( |
| 241 |
import_components.__experimentalVStack, |
| 242 |
{ |
| 243 |
spacing: 4, |
| 244 |
className: "connector-settings", |
| 245 |
style: readOnly ? { |
| 246 |
"--wp-components-color-background": "#f0f0f0" |
| 247 |
} : void 0, |
| 248 |
children |
| 249 |
} |
| 250 |
); |
| 251 |
} |
| 252 |
function ConnectorSettingsFooter({ |
| 253 |
readOnly, |
| 254 |
onRemove, |
| 255 |
canSave, |
| 256 |
isSaving, |
| 257 |
onSave |
| 258 |
}) { |
| 259 |
if (readOnly) { |
| 260 |
if (!onRemove) { |
| 261 |
return null; |
| 262 |
} |
| 263 |
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.__experimentalHStack, { justify: "flex-start", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Button, { variant: "link", isDestructive: true, onClick: onRemove, children: (0, import_i18n.__)("Remove and replace") }) }); |
| 264 |
} |
| 265 |
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.__experimentalHStack, { justify: "flex-start", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)( |
| 266 |
import_components.Button, |
| 267 |
{ |
| 268 |
__next40pxDefaultSize: true, |
| 269 |
variant: "primary", |
| 270 |
disabled: !canSave || isSaving, |
| 271 |
accessibleWhenDisabled: true, |
| 272 |
isBusy: isSaving, |
| 273 |
onClick: onSave, |
| 274 |
children: (0, import_i18n.__)("Save") |
| 275 |
} |
| 276 |
) }); |
| 277 |
} |
| 278 |
function DefaultConnectorSettings({ |
| 279 |
onSave, |
| 280 |
onRemove, |
| 281 |
initialValue = "", |
| 282 |
helpUrl, |
| 283 |
helpLabel, |
| 284 |
readOnly = false, |
| 285 |
keySource |
| 286 |
}) { |
| 287 |
const [apiKey, setApiKey] = (0, import_element.useState)(initialValue); |
| 288 |
const { isSaving, saveError, setSaveError, handleSave } = useConnectorSettingsSave( |
| 289 |
onSave, |
| 290 |
(0, import_i18n.__)( |
| 291 |
"It was not possible to connect to the provider using this key." |
| 292 |
) |
| 293 |
); |
| 294 |
const helpLink = createConnectorHelpLink( |
| 295 |
helpUrl, |
| 296 |
helpLabel, |
| 297 |
/* translators: %s: Link to provider settings. */ |
| 298 |
(0, import_i18n.__)("Get your API key at %s") |
| 299 |
); |
| 300 |
const isExternallyConfigured = keySource === "env" || keySource === "constant"; |
| 301 |
const getHelp = () => { |
| 302 |
if (isExternallyConfigured) { |
| 303 |
if (keySource === "env") { |
| 304 |
return (0, import_i18n.__)( |
| 305 |
"This API key is configured using an environment variable." |
| 306 |
); |
| 307 |
} |
| 308 |
if (keySource === "constant") { |
| 309 |
return (0, import_i18n.__)("This API key is configured as a constant."); |
| 310 |
} |
| 311 |
} |
| 312 |
if (readOnly) { |
| 313 |
return helpUrl ? createConnectorHelpLink( |
| 314 |
helpUrl, |
| 315 |
helpLabel, |
| 316 |
/* translators: %s: Link to provider settings. */ |
| 317 |
(0, import_i18n.__)( |
| 318 |
"Your API key is stored securely. You can manage it at %s" |
| 319 |
) |
| 320 |
) : (0, import_i18n.__)("Your API key is stored securely."); |
| 321 |
} |
| 322 |
if (saveError) { |
| 323 |
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { role: "alert", className: "connector-settings__error", children: saveError }); |
| 324 |
} |
| 325 |
return helpLink; |
| 326 |
}; |
| 327 |
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(ConnectorSettingsFrame, { readOnly, children: [ |
| 328 |
/* @__PURE__ */ (0, import_jsx_runtime.jsx)( |
| 329 |
import_components.TextControl, |
| 330 |
{ |
| 331 |
label: (0, import_i18n.__)("API Key"), |
| 332 |
value: apiKey, |
| 333 |
onChange: (value) => { |
| 334 |
if (!readOnly) { |
| 335 |
setSaveError(null); |
| 336 |
setApiKey(value); |
| 337 |
} |
| 338 |
}, |
| 339 |
placeholder: (0, import_i18n.__)("Enter your API key"), |
| 340 |
disabled: readOnly || isSaving, |
| 341 |
autoComplete: "off", |
| 342 |
help: getHelp() |
| 343 |
} |
| 344 |
), |
| 345 |
/* @__PURE__ */ (0, import_jsx_runtime.jsx)( |
| 346 |
ConnectorSettingsFooter, |
| 347 |
{ |
| 348 |
readOnly, |
| 349 |
onRemove, |
| 350 |
canSave: !!apiKey, |
| 351 |
isSaving, |
| 352 |
onSave: () => handleSave(apiKey) |
| 353 |
} |
| 354 |
) |
| 355 |
] }); |
| 356 |
} |
| 357 |
function ApplicationPasswordConnectorSettings({ |
| 358 |
onSave, |
| 359 |
onRemove, |
| 360 |
initialUsername = "", |
| 361 |
helpUrl, |
| 362 |
helpLabel, |
| 363 |
readOnly = false, |
| 364 |
keySource |
| 365 |
}) { |
| 366 |
const [username, setUsername] = (0, import_element.useState)(initialUsername); |
| 367 |
const [applicationPassword, setApplicationPassword] = (0, import_element.useState)(""); |
| 368 |
const { isSaving, saveError, setSaveError, handleSave } = useConnectorSettingsSave( |
| 369 |
onSave, |
| 370 |
(0, import_i18n.__)("It was not possible to save these credentials.") |
| 371 |
); |
| 372 |
const help = createConnectorHelpLink( |
| 373 |
helpUrl, |
| 374 |
helpLabel, |
| 375 |
/* translators: %s: Link to the remote site's application passwords screen. */ |
| 376 |
(0, import_i18n.__)("Create an application password at %s") |
| 377 |
); |
| 378 |
let applicationPasswordHelp = help; |
| 379 |
if (keySource === "env") { |
| 380 |
applicationPasswordHelp = (0, import_i18n.__)( |
| 381 |
"These credentials are configured using an environment variable." |
| 382 |
); |
| 383 |
} else if (keySource === "constant") { |
| 384 |
applicationPasswordHelp = (0, import_i18n.__)( |
| 385 |
"These credentials are configured as a constant." |
| 386 |
); |
| 387 |
} else if (readOnly) { |
| 388 |
applicationPasswordHelp = (0, import_i18n.__)( |
| 389 |
"Your application password is stored securely." |
| 390 |
); |
| 391 |
} |
| 392 |
if (saveError) { |
| 393 |
applicationPasswordHelp = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { role: "alert", className: "connector-settings__error", children: saveError }); |
| 394 |
} |
| 395 |
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(ConnectorSettingsFrame, { readOnly, children: [ |
| 396 |
/* @__PURE__ */ (0, import_jsx_runtime.jsx)( |
| 397 |
import_components.TextControl, |
| 398 |
{ |
| 399 |
label: (0, import_i18n.__)("Username"), |
| 400 |
value: username, |
| 401 |
onChange: (value) => { |
| 402 |
if (!readOnly) { |
| 403 |
setSaveError(null); |
| 404 |
setUsername(value); |
| 405 |
} |
| 406 |
}, |
| 407 |
placeholder: (0, import_i18n.__)("Enter your username"), |
| 408 |
disabled: readOnly || isSaving, |
| 409 |
autoComplete: "username" |
| 410 |
} |
| 411 |
), |
| 412 |
/* @__PURE__ */ (0, import_jsx_runtime.jsx)( |
| 413 |
import_components.TextControl, |
| 414 |
{ |
| 415 |
label: (0, import_i18n.__)("Application password"), |
| 416 |
value: readOnly ? "••••••••••••••••" : applicationPassword, |
| 417 |
onChange: (value) => { |
| 418 |
if (!readOnly) { |
| 419 |
setSaveError(null); |
| 420 |
setApplicationPassword(value); |
| 421 |
} |
| 422 |
}, |
| 423 |
type: "password", |
| 424 |
placeholder: (0, import_i18n.__)("Enter your application password"), |
| 425 |
disabled: readOnly || isSaving, |
| 426 |
autoComplete: "new-password", |
| 427 |
help: applicationPasswordHelp |
| 428 |
} |
| 429 |
), |
| 430 |
/* @__PURE__ */ (0, import_jsx_runtime.jsx)( |
| 431 |
ConnectorSettingsFooter, |
| 432 |
{ |
| 433 |
readOnly, |
| 434 |
onRemove, |
| 435 |
canSave: !!username.trim() && !!applicationPassword, |
| 436 |
isSaving, |
| 437 |
onSave: () => handleSave({ |
| 438 |
username: username.trim(), |
| 439 |
applicationPassword |
| 440 |
}) |
| 441 |
} |
| 442 |
) |
| 443 |
] }); |
| 444 |
} |
| 445 |
|
| 446 |
// packages/connectors/build-module/private-apis.mjs |
| 447 |
var privateApis = {}; |
| 448 |
lock(privateApis, { store, STORE_NAME }); |
| 449 |
export { |
| 450 |
ApplicationPasswordConnectorSettings as __experimentalApplicationPasswordConnectorSettings, |
| 451 |
ConnectorItem as __experimentalConnectorItem, |
| 452 |
DefaultConnectorSettings as __experimentalDefaultConnectorSettings, |
| 453 |
registerConnector as __experimentalRegisterConnector, |
| 454 |
unregisterConnector as __experimentalUnregisterConnector, |
| 455 |
privateApis |
| 456 |
}; |
| 457 |
//# sourceMappingURL=index.js.map |
| 458 |
|