first commit
This commit is contained in:
318
wp-includes/js/dist/script-modules/connectors/index.js
vendored
Normal file
318
wp-includes/js/dist/script-modules/connectors/index.js
vendored
Normal file
@@ -0,0 +1,318 @@
|
||||
var __create = Object.create;
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __getProtoOf = Object.getPrototypeOf;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __commonJS = (cb, mod) => function __require() {
|
||||
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
||||
// If the importer is in node compatibility mode or this is not an ESM
|
||||
// file that has been converted to a CommonJS file using a Babel-
|
||||
// compatible transform (i.e. "__esModule" has not been set), then set
|
||||
// "default" to the CommonJS "module.exports" for node compatibility.
|
||||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
||||
mod
|
||||
));
|
||||
|
||||
// package-external:@wordpress/data
|
||||
var require_data = __commonJS({
|
||||
"package-external:@wordpress/data"(exports, module) {
|
||||
module.exports = window.wp.data;
|
||||
}
|
||||
});
|
||||
|
||||
// package-external:@wordpress/private-apis
|
||||
var require_private_apis = __commonJS({
|
||||
"package-external:@wordpress/private-apis"(exports, module) {
|
||||
module.exports = window.wp.privateApis;
|
||||
}
|
||||
});
|
||||
|
||||
// package-external:@wordpress/components
|
||||
var require_components = __commonJS({
|
||||
"package-external:@wordpress/components"(exports, module) {
|
||||
module.exports = window.wp.components;
|
||||
}
|
||||
});
|
||||
|
||||
// package-external:@wordpress/element
|
||||
var require_element = __commonJS({
|
||||
"package-external:@wordpress/element"(exports, module) {
|
||||
module.exports = window.wp.element;
|
||||
}
|
||||
});
|
||||
|
||||
// package-external:@wordpress/i18n
|
||||
var require_i18n = __commonJS({
|
||||
"package-external:@wordpress/i18n"(exports, module) {
|
||||
module.exports = window.wp.i18n;
|
||||
}
|
||||
});
|
||||
|
||||
// vendor-external:react/jsx-runtime
|
||||
var require_jsx_runtime = __commonJS({
|
||||
"vendor-external:react/jsx-runtime"(exports, module) {
|
||||
module.exports = window.ReactJSXRuntime;
|
||||
}
|
||||
});
|
||||
|
||||
// packages/connectors/build-module/api.mjs
|
||||
var import_data2 = __toESM(require_data(), 1);
|
||||
|
||||
// packages/connectors/build-module/store.mjs
|
||||
var import_data = __toESM(require_data(), 1);
|
||||
|
||||
// packages/connectors/build-module/lock-unlock.mjs
|
||||
var import_private_apis = __toESM(require_private_apis(), 1);
|
||||
var { lock, unlock } = (0, import_private_apis.__dangerousOptInToUnstableAPIsOnlyForCoreModules)(
|
||||
"I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.",
|
||||
"@wordpress/connectors"
|
||||
);
|
||||
|
||||
// packages/connectors/build-module/store.mjs
|
||||
var STORE_NAME = "core/connectors";
|
||||
var DEFAULT_STATE = {
|
||||
connectors: {}
|
||||
};
|
||||
var actions = {
|
||||
registerConnector(slug, config) {
|
||||
return {
|
||||
type: "REGISTER_CONNECTOR",
|
||||
slug,
|
||||
config
|
||||
};
|
||||
},
|
||||
unregisterConnector(slug) {
|
||||
return {
|
||||
type: "UNREGISTER_CONNECTOR",
|
||||
slug
|
||||
};
|
||||
}
|
||||
};
|
||||
function reducer(state = DEFAULT_STATE, action) {
|
||||
switch (action.type) {
|
||||
case "REGISTER_CONNECTOR":
|
||||
return {
|
||||
...state,
|
||||
connectors: {
|
||||
...state.connectors,
|
||||
[action.slug]: {
|
||||
...state.connectors[action.slug],
|
||||
slug: action.slug,
|
||||
...action.config
|
||||
}
|
||||
}
|
||||
};
|
||||
case "UNREGISTER_CONNECTOR": {
|
||||
if (!state.connectors[action.slug]) {
|
||||
return state;
|
||||
}
|
||||
const { [action.slug]: _, ...rest } = state.connectors;
|
||||
return {
|
||||
...state,
|
||||
connectors: rest
|
||||
};
|
||||
}
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
var selectors = {
|
||||
getConnectors: (0, import_data.createSelector)(
|
||||
(state) => Object.values(state.connectors),
|
||||
(state) => [state.connectors]
|
||||
),
|
||||
getConnector(state, slug) {
|
||||
return state.connectors[slug];
|
||||
}
|
||||
};
|
||||
var store = (0, import_data.createReduxStore)(STORE_NAME, {
|
||||
reducer
|
||||
});
|
||||
(0, import_data.register)(store);
|
||||
unlock(store).registerPrivateActions(actions);
|
||||
unlock(store).registerPrivateSelectors(selectors);
|
||||
|
||||
// packages/connectors/build-module/api.mjs
|
||||
function registerConnector(slug, config) {
|
||||
unlock((0, import_data2.dispatch)(store)).registerConnector(slug, config);
|
||||
}
|
||||
function unregisterConnector(slug) {
|
||||
unlock((0, import_data2.dispatch)(store)).unregisterConnector(slug);
|
||||
}
|
||||
|
||||
// packages/connectors/build-module/connector-item.mjs
|
||||
var import_components = __toESM(require_components(), 1);
|
||||
var import_element = __toESM(require_element(), 1);
|
||||
var import_i18n = __toESM(require_i18n(), 1);
|
||||
var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
|
||||
function ConnectorItem({
|
||||
className,
|
||||
logo,
|
||||
name,
|
||||
description,
|
||||
actionArea,
|
||||
children
|
||||
}) {
|
||||
const headingId = (0, import_element.useId)();
|
||||
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: [
|
||||
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalHStack, { alignment: "center", spacing: 4, wrap: true, children: [
|
||||
logo,
|
||||
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.FlexBlock, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalVStack, { spacing: 0, children: [
|
||||
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
||||
import_components.__experimentalText,
|
||||
{
|
||||
weight: 600,
|
||||
size: 15,
|
||||
id: headingId,
|
||||
as: "h2",
|
||||
children: name
|
||||
}
|
||||
),
|
||||
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.__experimentalText, { variant: "muted", size: 12, children: description })
|
||||
] }) }),
|
||||
actionArea
|
||||
] }),
|
||||
children
|
||||
] }) });
|
||||
}
|
||||
function DefaultConnectorSettings({
|
||||
onSave,
|
||||
onRemove,
|
||||
initialValue = "",
|
||||
helpUrl,
|
||||
helpLabel,
|
||||
readOnly = false,
|
||||
keySource
|
||||
}) {
|
||||
const [apiKey, setApiKey] = (0, import_element.useState)(initialValue);
|
||||
const [isSaving, setIsSaving] = (0, import_element.useState)(false);
|
||||
const [saveError, setSaveError] = (0, import_element.useState)(null);
|
||||
const helpLinkLabel = helpLabel || helpUrl?.replace(/^https?:\/\//, "");
|
||||
const helpLink = helpUrl ? (0, import_element.createInterpolateElement)(
|
||||
(0, import_i18n.sprintf)(
|
||||
/* translators: %s: Link to provider settings. */
|
||||
(0, import_i18n.__)("Get your API key at %s"),
|
||||
"<a></a>"
|
||||
),
|
||||
{
|
||||
a: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.ExternalLink, { href: helpUrl, children: helpLinkLabel })
|
||||
}
|
||||
) : void 0;
|
||||
const isExternallyConfigured = keySource === "env" || keySource === "constant";
|
||||
const getHelp = () => {
|
||||
if (isExternallyConfigured) {
|
||||
if (keySource === "env") {
|
||||
return (0, import_i18n.__)(
|
||||
"This API key is configured using an environment variable."
|
||||
);
|
||||
}
|
||||
if (keySource === "constant") {
|
||||
return (0, import_i18n.__)("This API key is configured as a constant.");
|
||||
}
|
||||
}
|
||||
if (readOnly) {
|
||||
return helpUrl ? (0, import_element.createInterpolateElement)(
|
||||
(0, import_i18n.sprintf)(
|
||||
/* translators: %s: Link to provider settings. */
|
||||
(0, import_i18n.__)(
|
||||
"Your API key is stored securely. You can manage it at %s"
|
||||
),
|
||||
"<a></a>"
|
||||
),
|
||||
{
|
||||
a: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.ExternalLink, { href: helpUrl, children: helpLinkLabel })
|
||||
}
|
||||
) : (0, import_i18n.__)("Your API key is stored securely.");
|
||||
}
|
||||
if (saveError) {
|
||||
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { role: "alert", className: "connector-settings__error", children: saveError });
|
||||
}
|
||||
return helpLink;
|
||||
};
|
||||
const handleSave = async () => {
|
||||
setSaveError(null);
|
||||
setIsSaving(true);
|
||||
try {
|
||||
await onSave?.(apiKey);
|
||||
} catch (error) {
|
||||
setSaveError(
|
||||
error instanceof Error ? error.message : (0, import_i18n.__)(
|
||||
"It was not possible to connect to the provider using this key."
|
||||
)
|
||||
);
|
||||
} finally {
|
||||
setIsSaving(false);
|
||||
}
|
||||
};
|
||||
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
||||
import_components.__experimentalVStack,
|
||||
{
|
||||
spacing: 4,
|
||||
className: "connector-settings",
|
||||
style: readOnly ? {
|
||||
"--wp-components-color-background": "#f0f0f0"
|
||||
} : void 0,
|
||||
children: [
|
||||
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
||||
import_components.TextControl,
|
||||
{
|
||||
__next40pxDefaultSize: true,
|
||||
label: (0, import_i18n.__)("API Key"),
|
||||
value: apiKey,
|
||||
onChange: (value) => {
|
||||
if (!readOnly) {
|
||||
setSaveError(null);
|
||||
setApiKey(value);
|
||||
}
|
||||
},
|
||||
placeholder: (0, import_i18n.__)("Enter your API key"),
|
||||
disabled: readOnly || isSaving,
|
||||
help: getHelp()
|
||||
}
|
||||
),
|
||||
readOnly ? onRemove && /* @__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")
|
||||
}
|
||||
) }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.__experimentalHStack, { justify: "flex-start", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
||||
import_components.Button,
|
||||
{
|
||||
__next40pxDefaultSize: true,
|
||||
variant: "primary",
|
||||
disabled: !apiKey || isSaving,
|
||||
accessibleWhenDisabled: true,
|
||||
isBusy: isSaving,
|
||||
onClick: handleSave,
|
||||
children: (0, import_i18n.__)("Save")
|
||||
}
|
||||
) })
|
||||
]
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// packages/connectors/build-module/private-apis.mjs
|
||||
var privateApis = {};
|
||||
lock(privateApis, { store, STORE_NAME });
|
||||
export {
|
||||
ConnectorItem as __experimentalConnectorItem,
|
||||
DefaultConnectorSettings as __experimentalDefaultConnectorSettings,
|
||||
registerConnector as __experimentalRegisterConnector,
|
||||
unregisterConnector as __experimentalUnregisterConnector,
|
||||
privateApis
|
||||
};
|
||||
1
wp-includes/js/dist/script-modules/connectors/index.min.asset.php
vendored
Normal file
1
wp-includes/js/dist/script-modules/connectors/index.min.asset.php
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<?php return array('dependencies' => array('react-jsx-runtime', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-private-apis'), 'version' => '274797868955a828dfdc');
|
||||
1
wp-includes/js/dist/script-modules/connectors/index.min.js
vendored
Normal file
1
wp-includes/js/dist/script-modules/connectors/index.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
var W=Object.create;var y=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var X=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var f=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports);var Q=(e,r,i,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let c of U(r))!q.call(e,c)&&c!==i&&y(e,c,{get:()=>r[c],enumerable:!(s=J(r,c))||s.enumerable});return e};var m=(e,r,i)=>(i=e!=null?W(X(e)):{},Q(r||!e||!e.__esModule?y(i,"default",{value:e,enumerable:!0}):i,e));var C=f((ce,T)=>{T.exports=window.wp.data});var A=f((ae,R)=>{R.exports=window.wp.privateApis});var O=f((ge,P)=>{P.exports=window.wp.components});var j=f((xe,D)=>{D.exports=window.wp.element});var L=f((_e,G)=>{G.exports=window.wp.i18n});var B=f((he,z)=>{z.exports=window.ReactJSXRuntime});var E=m(C(),1);var g=m(C(),1);var b=m(A(),1),{lock:N,unlock:d}=(0,b.__dangerousOptInToUnstableAPIsOnlyForCoreModules)("I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.","@wordpress/connectors");var w="core/connectors",Z={connectors:{}},$={registerConnector(e,r){return{type:"REGISTER_CONNECTOR",slug:e,config:r}},unregisterConnector(e){return{type:"UNREGISTER_CONNECTOR",slug:e}}};function ee(e=Z,r){switch(r.type){case"REGISTER_CONNECTOR":return{...e,connectors:{...e.connectors,[r.slug]:{...e.connectors[r.slug],slug:r.slug,...r.config}}};case"UNREGISTER_CONNECTOR":{if(!e.connectors[r.slug])return e;let{[r.slug]:i,...s}=e.connectors;return{...e,connectors:s}}default:return e}}var re={getConnectors:(0,g.createSelector)(e=>Object.values(e.connectors),e=>[e.connectors]),getConnector(e,r){return e.connectors[r]}},l=(0,g.createReduxStore)(w,{reducer:ee});(0,g.register)(l);d(l).registerPrivateActions($);d(l).registerPrivateSelectors(re);function te(e,r){d((0,E.dispatch)(l)).registerConnector(e,r)}function ne(e){d((0,E.dispatch)(l)).unregisterConnector(e)}var t=m(O(),1),a=m(j(),1),o=m(L(),1),n=m(B(),1);function oe({className:e,logo:r,name:i,description:s,actionArea:c,children:p}){let u=(0,a.useId)();return(0,n.jsx)(t.__experimentalItem,{className:e,children:(0,n.jsxs)(t.__experimentalVStack,{spacing:4,role:"group","aria-labelledby":u,children:[(0,n.jsxs)(t.__experimentalHStack,{alignment:"center",spacing:4,wrap:!0,children:[r,(0,n.jsx)(t.FlexBlock,{children:(0,n.jsxs)(t.__experimentalVStack,{spacing:0,children:[(0,n.jsx)(t.__experimentalText,{weight:600,size:15,id:u,as:"h2",children:i}),(0,n.jsx)(t.__experimentalText,{variant:"muted",size:12,children:s})]})}),c]}),p]})})}function se({onSave:e,onRemove:r,initialValue:i="",helpUrl:s,helpLabel:c,readOnly:p=!1,keySource:u}){let[_,H]=(0,a.useState)(i),[h,I]=(0,a.useState)(!1),[k,v]=(0,a.useState)(null),S=c||s?.replace(/^https?:\/\//,""),K=s?(0,a.createInterpolateElement)((0,o.sprintf)((0,o.__)("Get your API key at %s"),"<a></a>"),{a:(0,n.jsx)(t.ExternalLink,{href:s,children:S})}):void 0,M=u==="env"||u==="constant",Y=()=>{if(M){if(u==="env")return(0,o.__)("This API key is configured using an environment variable.");if(u==="constant")return(0,o.__)("This API key is configured as a constant.")}return p?s?(0,a.createInterpolateElement)((0,o.sprintf)((0,o.__)("Your API key is stored securely. You can manage it at %s"),"<a></a>"),{a:(0,n.jsx)(t.ExternalLink,{href:s,children:S})}):(0,o.__)("Your API key is stored securely."):k?(0,n.jsx)("span",{role:"alert",className:"connector-settings__error",children:k}):K},V=async()=>{v(null),I(!0);try{await e?.(_)}catch(x){v(x instanceof Error?x.message:(0,o.__)("It was not possible to connect to the provider using this key."))}finally{I(!1)}};return(0,n.jsxs)(t.__experimentalVStack,{spacing:4,className:"connector-settings",style:p?{"--wp-components-color-background":"#f0f0f0"}:void 0,children:[(0,n.jsx)(t.TextControl,{__next40pxDefaultSize:!0,label:(0,o.__)("API Key"),value:_,onChange:x=>{p||(v(null),H(x))},placeholder:(0,o.__)("Enter your API key"),disabled:p||h,help:Y()}),p?r&&(0,n.jsx)(t.__experimentalHStack,{justify:"flex-start",children:(0,n.jsx)(t.Button,{variant:"link",isDestructive:!0,onClick:r,children:(0,o.__)("Remove and replace")})}):(0,n.jsx)(t.__experimentalHStack,{justify:"flex-start",children:(0,n.jsx)(t.Button,{__next40pxDefaultSize:!0,variant:"primary",disabled:!_||h,accessibleWhenDisabled:!0,isBusy:h,onClick:V,children:(0,o.__)("Save")})})]})}var F={};N(F,{store:l,STORE_NAME:w});export{oe as __experimentalConnectorItem,se as __experimentalDefaultConnectorSettings,te as __experimentalRegisterConnector,ne as __experimentalUnregisterConnector,F as privateApis};
|
||||
Reference in New Issue
Block a user