[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/js/dist/ -> plugins.js (source)

   1  (function() {
   2  "use strict";
   3  var wp;
   4  (wp ||= {}).plugins = (() => {
   5    var __create = Object.create;
   6    var __defProp = Object.defineProperty;
   7    var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
   8    var __getOwnPropNames = Object.getOwnPropertyNames;
   9    var __getProtoOf = Object.getPrototypeOf;
  10    var __hasOwnProp = Object.prototype.hasOwnProperty;
  11    var __commonJS = (cb, mod) => function __require() {
  12      return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
  13    };
  14    var __export = (target, all) => {
  15      for (var name in all)
  16        __defProp(target, name, { get: all[name], enumerable: true });
  17    };
  18    var __copyProps = (to, from, except, desc) => {
  19      if (from && typeof from === "object" || typeof from === "function") {
  20        for (let key of __getOwnPropNames(from))
  21          if (!__hasOwnProp.call(to, key) && key !== except)
  22            __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  23      }
  24      return to;
  25    };
  26    var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  27      // If the importer is in node compatibility mode or this is not an ESM
  28      // file that has been converted to a CommonJS file using a Babel-
  29      // compatible transform (i.e. "__esModule" has not been set), then set
  30      // "default" to the CommonJS "module.exports" for node compatibility.
  31      isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  32      mod
  33    ));
  34    var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  35  
  36    // package-external:@wordpress/element
  37    var require_element = __commonJS({
  38      "package-external:@wordpress/element"(exports, module) {
  39        module.exports = window.wp.element;
  40      }
  41    });
  42  
  43    // package-external:@wordpress/hooks
  44    var require_hooks = __commonJS({
  45      "package-external:@wordpress/hooks"(exports, module) {
  46        module.exports = window.wp.hooks;
  47      }
  48    });
  49  
  50    // package-external:@wordpress/is-shallow-equal
  51    var require_is_shallow_equal = __commonJS({
  52      "package-external:@wordpress/is-shallow-equal"(exports, module) {
  53        module.exports = window.wp.isShallowEqual;
  54      }
  55    });
  56  
  57    // package-external:@wordpress/compose
  58    var require_compose = __commonJS({
  59      "package-external:@wordpress/compose"(exports, module) {
  60        module.exports = window.wp.compose;
  61      }
  62    });
  63  
  64    // package-external:@wordpress/deprecated
  65    var require_deprecated = __commonJS({
  66      "package-external:@wordpress/deprecated"(exports, module) {
  67        module.exports = window.wp.deprecated;
  68      }
  69    });
  70  
  71    // vendor-external:react/jsx-runtime
  72    var require_jsx_runtime = __commonJS({
  73      "vendor-external:react/jsx-runtime"(exports, module) {
  74        module.exports = window.ReactJSXRuntime;
  75      }
  76    });
  77  
  78    // node_modules/.store/react-is@19.3.0-h9DBeE4BCfrMSfxZZXEDFw/node_modules/react-is/cjs/react-is.development.js
  79    var require_react_is_development = __commonJS({
  80      "node_modules/.store/react-is@19.3.0-h9DBeE4BCfrMSfxZZXEDFw/node_modules/react-is/cjs/react-is.development.js"(exports) {
  81        "use strict";
  82        (function() {
  83          function typeOf(object) {
  84            if ("object" === typeof object && null !== object) {
  85              var $$typeof = object.$$typeof;
  86              switch ($$typeof) {
  87                case REACT_ELEMENT_TYPE:
  88                  switch (object = object.type, object) {
  89                    case REACT_FRAGMENT_TYPE:
  90                    case REACT_PROFILER_TYPE:
  91                    case REACT_STRICT_MODE_TYPE:
  92                    case REACT_SUSPENSE_TYPE:
  93                    case REACT_SUSPENSE_LIST_TYPE:
  94                    case REACT_VIEW_TRANSITION_TYPE:
  95                      return object;
  96                    default:
  97                      switch (object = object && object.$$typeof, object) {
  98                        case REACT_CONTEXT_TYPE:
  99                        case REACT_FORWARD_REF_TYPE:
 100                        case REACT_LAZY_TYPE:
 101                        case REACT_MEMO_TYPE:
 102                          return object;
 103                        case REACT_CONSUMER_TYPE:
 104                          return object;
 105                        default:
 106                          return $$typeof;
 107                      }
 108                  }
 109                case REACT_PORTAL_TYPE:
 110                  return $$typeof;
 111              }
 112            }
 113          }
 114          var REACT_ELEMENT_TYPE = /* @__PURE__ */ Symbol.for("react.transitional.element"), REACT_PORTAL_TYPE = /* @__PURE__ */ Symbol.for("react.portal"), REACT_FRAGMENT_TYPE = /* @__PURE__ */ Symbol.for("react.fragment"), REACT_STRICT_MODE_TYPE = /* @__PURE__ */ Symbol.for("react.strict_mode"), REACT_PROFILER_TYPE = /* @__PURE__ */ Symbol.for("react.profiler"), REACT_CONSUMER_TYPE = /* @__PURE__ */ Symbol.for("react.consumer"), REACT_CONTEXT_TYPE = /* @__PURE__ */ Symbol.for("react.context"), REACT_FORWARD_REF_TYPE = /* @__PURE__ */ Symbol.for("react.forward_ref"), REACT_SUSPENSE_TYPE = /* @__PURE__ */ Symbol.for("react.suspense"), REACT_SUSPENSE_LIST_TYPE = /* @__PURE__ */ Symbol.for("react.suspense_list"), REACT_MEMO_TYPE = /* @__PURE__ */ Symbol.for("react.memo"), REACT_LAZY_TYPE = /* @__PURE__ */ Symbol.for("react.lazy"), REACT_VIEW_TRANSITION_TYPE = /* @__PURE__ */ Symbol.for("react.view_transition"), REACT_CLIENT_REFERENCE = /* @__PURE__ */ Symbol.for("react.client.reference");
 115          exports.ContextConsumer = REACT_CONSUMER_TYPE;
 116          exports.ContextProvider = REACT_CONTEXT_TYPE;
 117          exports.Element = REACT_ELEMENT_TYPE;
 118          exports.ForwardRef = REACT_FORWARD_REF_TYPE;
 119          exports.Fragment = REACT_FRAGMENT_TYPE;
 120          exports.Lazy = REACT_LAZY_TYPE;
 121          exports.Memo = REACT_MEMO_TYPE;
 122          exports.Portal = REACT_PORTAL_TYPE;
 123          exports.Profiler = REACT_PROFILER_TYPE;
 124          exports.StrictMode = REACT_STRICT_MODE_TYPE;
 125          exports.Suspense = REACT_SUSPENSE_TYPE;
 126          exports.SuspenseList = REACT_SUSPENSE_LIST_TYPE;
 127          exports.isContextConsumer = function(object) {
 128            return typeOf(object) === REACT_CONSUMER_TYPE;
 129          };
 130          exports.isContextProvider = function(object) {
 131            return typeOf(object) === REACT_CONTEXT_TYPE;
 132          };
 133          exports.isElement = function(object) {
 134            return "object" === typeof object && null !== object && object.$$typeof === REACT_ELEMENT_TYPE;
 135          };
 136          exports.isForwardRef = function(object) {
 137            return typeOf(object) === REACT_FORWARD_REF_TYPE;
 138          };
 139          exports.isFragment = function(object) {
 140            return typeOf(object) === REACT_FRAGMENT_TYPE;
 141          };
 142          exports.isLazy = function(object) {
 143            return typeOf(object) === REACT_LAZY_TYPE;
 144          };
 145          exports.isMemo = function(object) {
 146            return typeOf(object) === REACT_MEMO_TYPE;
 147          };
 148          exports.isPortal = function(object) {
 149            return typeOf(object) === REACT_PORTAL_TYPE;
 150          };
 151          exports.isProfiler = function(object) {
 152            return typeOf(object) === REACT_PROFILER_TYPE;
 153          };
 154          exports.isStrictMode = function(object) {
 155            return typeOf(object) === REACT_STRICT_MODE_TYPE;
 156          };
 157          exports.isSuspense = function(object) {
 158            return typeOf(object) === REACT_SUSPENSE_TYPE;
 159          };
 160          exports.isSuspenseList = function(object) {
 161            return typeOf(object) === REACT_SUSPENSE_LIST_TYPE;
 162          };
 163          exports.isValidElementType = function(type) {
 164            return "string" === typeof type || "function" === typeof type || type === REACT_FRAGMENT_TYPE || type === REACT_PROFILER_TYPE || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_TYPE || type === REACT_VIEW_TRANSITION_TYPE || "object" === typeof type && null !== type && (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_CONSUMER_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE || type.$$typeof === REACT_CLIENT_REFERENCE || void 0 !== type.getModuleId) ? true : false;
 165          };
 166          exports.typeOf = typeOf;
 167        })();
 168      }
 169    });
 170  
 171    // node_modules/.store/react-is@19.3.0-h9DBeE4BCfrMSfxZZXEDFw/node_modules/react-is/index.js
 172    var require_react_is = __commonJS({
 173      "node_modules/.store/react-is@19.3.0-h9DBeE4BCfrMSfxZZXEDFw/node_modules/react-is/index.js"(exports, module) {
 174        "use strict";
 175        if (false) {
 176          module.exports = null;
 177        } else {
 178          module.exports = require_react_is_development();
 179        }
 180      }
 181    });
 182  
 183    // package-external:@wordpress/primitives
 184    var require_primitives = __commonJS({
 185      "package-external:@wordpress/primitives"(exports, module) {
 186        module.exports = window.wp.primitives;
 187      }
 188    });
 189  
 190    // packages/plugins/build-module/index.mjs
 191    var index_exports = {};
 192    __export(index_exports, {
 193      PluginArea: () => plugin_area_default,
 194      getPlugin: () => getPlugin,
 195      getPlugins: () => getPlugins,
 196      registerPlugin: () => registerPlugin,
 197      unregisterPlugin: () => unregisterPlugin,
 198      usePluginContext: () => usePluginContext,
 199      withPluginContext: () => withPluginContext
 200    });
 201  
 202    // node_modules/.store/memize@2.1.1-roXbtpG2bis3Lggp7SQpAA/node_modules/memize/dist/index.js
 203    function memize(fn, options) {
 204      var size = 0;
 205      var head;
 206      var tail;
 207      options = options || {};
 208      function memoized() {
 209        var node = head, len = arguments.length, args, i;
 210        searchCache: while (node) {
 211          if (node.args.length !== arguments.length) {
 212            node = node.next;
 213            continue;
 214          }
 215          for (i = 0; i < len; i++) {
 216            if (node.args[i] !== arguments[i]) {
 217              node = node.next;
 218              continue searchCache;
 219            }
 220          }
 221          if (node !== head) {
 222            if (node === tail) {
 223              tail = node.prev;
 224            }
 225            node.prev.next = node.next;
 226            if (node.next) {
 227              node.next.prev = node.prev;
 228            }
 229            node.next = head;
 230            node.prev = null;
 231            head.prev = node;
 232            head = node;
 233          }
 234          return node.val;
 235        }
 236        args = new Array(len);
 237        for (i = 0; i < len; i++) {
 238          args[i] = arguments[i];
 239        }
 240        node = {
 241          args,
 242          // Generate the result from original function
 243          val: fn.apply(null, args)
 244        };
 245        if (head) {
 246          head.prev = node;
 247          node.next = head;
 248        } else {
 249          tail = node;
 250        }
 251        if (size === /** @type {MemizeOptions} */
 252        options.maxSize) {
 253          tail = /** @type {MemizeCacheNode} */
 254          tail.prev;
 255          tail.next = null;
 256        } else {
 257          size++;
 258        }
 259        head = node;
 260        return node.val;
 261      }
 262      memoized.clear = function() {
 263        head = null;
 264        tail = null;
 265        size = 0;
 266      };
 267      return memoized;
 268    }
 269  
 270    // packages/plugins/build-module/components/plugin-area/index.mjs
 271    var import_element3 = __toESM(require_element(), 1);
 272    var import_hooks2 = __toESM(require_hooks(), 1);
 273    var import_is_shallow_equal = __toESM(require_is_shallow_equal(), 1);
 274  
 275    // packages/plugins/build-module/components/plugin-context/index.mjs
 276    var import_element = __toESM(require_element(), 1);
 277    var import_compose = __toESM(require_compose(), 1);
 278    var import_deprecated = __toESM(require_deprecated(), 1);
 279    var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
 280    var Context = (0, import_element.createContext)({
 281      name: null,
 282      icon: null
 283    });
 284    Context.displayName = "PluginContext";
 285    var PluginContextProvider = Context.Provider;
 286    function usePluginContext() {
 287      return (0, import_element.useContext)(Context);
 288    }
 289    var withPluginContext = (mapContextToProps) => (0, import_compose.createHigherOrderComponent)((OriginalComponent) => {
 290      (0, import_deprecated.default)("wp.plugins.withPluginContext", {
 291        since: "6.8.0",
 292        alternative: "wp.plugins.usePluginContext"
 293      });
 294      return (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Context.Consumer, { children: (context) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
 295        OriginalComponent,
 296        {
 297          ...props,
 298          ...mapContextToProps(context, props)
 299        }
 300      ) });
 301    }, "withPluginContext");
 302  
 303    // packages/plugins/build-module/components/plugin-error-boundary/index.mjs
 304    var import_element2 = __toESM(require_element(), 1);
 305    var PluginErrorBoundary = class extends import_element2.Component {
 306      constructor(props) {
 307        super(props);
 308        this.state = {
 309          hasError: false
 310        };
 311      }
 312      static getDerivedStateFromError() {
 313        return { hasError: true };
 314      }
 315      componentDidCatch(error) {
 316        const { name, onError } = this.props;
 317        if (onError) {
 318          onError(name, error);
 319        }
 320      }
 321      render() {
 322        if (!this.state.hasError) {
 323          return this.props.children;
 324        }
 325        return null;
 326      }
 327    };
 328  
 329    // packages/plugins/build-module/api/index.mjs
 330    var import_react_is = __toESM(require_react_is(), 1);
 331    var import_hooks = __toESM(require_hooks(), 1);
 332  
 333    // packages/icons/build-module/library/plugins.mjs
 334    var import_primitives = __toESM(require_primitives(), 1);
 335    var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
 336    var plugins_default = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_primitives.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", style: { fill: "none" }, stroke: "currentColor", strokeWidth: "1.5", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_primitives.Path, { d: "M15.3995 11.5711L12.2175 8.38909L10.273 6.44454L7.67678 9.04074C7.3017 9.41581 7.09099 9.92452 7.09099 10.455L7.09099 13.455C7.09099 13.7202 6.98563 13.9745 6.7981 14.1621L5.14645 15.8137C4.95118 16.009 4.95118 16.3256 5.14645 16.5208L7.26777 18.6421C7.46303 18.8374 7.77961 18.8374 7.97487 18.6421L9.62652 16.9905C9.81406 16.8029 10.0684 16.6976 10.3336 16.6976H13.3336C13.8641 16.6976 14.3728 16.4869 14.7478 16.1118L17.344 13.5156L15.3995 11.5711ZM12.2175 8.38909L16.1066 4.5M15.3995 11.5711L19.2886 7.68198" }) });
 337  
 338    // packages/plugins/build-module/api/index.mjs
 339    var plugins = {};
 340    function registerPlugin(name, settings) {
 341      if (typeof settings !== "object") {
 342        console.error("No settings object provided!");
 343        return null;
 344      }
 345      if (typeof name !== "string") {
 346        console.error("Plugin name must be string.");
 347        return null;
 348      }
 349      if (!/^[a-z][a-z0-9-]*$/.test(name)) {
 350        console.error(
 351          'Plugin name must include only lowercase alphanumeric characters or dashes, and start with a letter. Example: "my-plugin".'
 352        );
 353        return null;
 354      }
 355      if (plugins[name]) {
 356        console.error(`Plugin "$name}" is already registered.`);
 357      }
 358      settings = (0, import_hooks.applyFilters)(
 359        "plugins.registerPlugin",
 360        settings,
 361        name
 362      );
 363      const { render, scope } = settings;
 364      if (!(0, import_react_is.isValidElementType)(render)) {
 365        console.error(
 366          'The "render" property must be specified and must be a valid component.'
 367        );
 368        return null;
 369      }
 370      if (scope) {
 371        if (typeof scope !== "string") {
 372          console.error("Plugin scope must be string.");
 373          return null;
 374        }
 375        if (!/^[a-z][a-z0-9-]*$/.test(scope)) {
 376          console.error(
 377            'Plugin scope must include only lowercase alphanumeric characters or dashes, and start with a letter. Example: "my-page".'
 378          );
 379          return null;
 380        }
 381      }
 382      plugins[name] = {
 383        name,
 384        icon: plugins_default,
 385        ...settings
 386      };
 387      (0, import_hooks.doAction)("plugins.pluginRegistered", settings, name);
 388      return settings;
 389    }
 390    function unregisterPlugin(name) {
 391      if (!plugins[name]) {
 392        console.error('Plugin "' + name + '" is not registered.');
 393        return;
 394      }
 395      const oldPlugin = plugins[name];
 396      delete plugins[name];
 397      (0, import_hooks.doAction)("plugins.pluginUnregistered", oldPlugin, name);
 398      return oldPlugin;
 399    }
 400    function getPlugin(name) {
 401      return plugins[name];
 402    }
 403    function getPlugins(scope) {
 404      return Object.values(plugins).filter(
 405        (plugin) => plugin.scope === scope
 406      );
 407    }
 408  
 409    // packages/plugins/build-module/components/plugin-area/index.mjs
 410    var import_jsx_runtime3 = __toESM(require_jsx_runtime(), 1);
 411    var getPluginContext = memize(
 412      (icon, name) => ({
 413        icon,
 414        name
 415      })
 416    );
 417    function PluginArea({
 418      scope,
 419      onError
 420    }) {
 421      const store = (0, import_element3.useMemo)(() => {
 422        let lastValue = [];
 423        return {
 424          subscribe(listener) {
 425            (0, import_hooks2.addAction)(
 426              "plugins.pluginRegistered",
 427              "core/plugins/plugin-area/plugins-registered",
 428              listener
 429            );
 430            (0, import_hooks2.addAction)(
 431              "plugins.pluginUnregistered",
 432              "core/plugins/plugin-area/plugins-unregistered",
 433              listener
 434            );
 435            return () => {
 436              (0, import_hooks2.removeAction)(
 437                "plugins.pluginRegistered",
 438                "core/plugins/plugin-area/plugins-registered"
 439              );
 440              (0, import_hooks2.removeAction)(
 441                "plugins.pluginUnregistered",
 442                "core/plugins/plugin-area/plugins-unregistered"
 443              );
 444            };
 445          },
 446          getValue() {
 447            const nextValue = getPlugins(scope);
 448            if (!(0, import_is_shallow_equal.isShallowEqual)(lastValue, nextValue)) {
 449              lastValue = nextValue;
 450            }
 451            return lastValue;
 452          }
 453        };
 454      }, [scope]);
 455      const plugins2 = (0, import_element3.useSyncExternalStore)(
 456        store.subscribe,
 457        store.getValue,
 458        store.getValue
 459      );
 460      return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { display: "none" }, children: plugins2.map(({ icon, name, render: Plugin }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
 461        PluginContextProvider,
 462        {
 463          value: getPluginContext(icon, name),
 464          children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(PluginErrorBoundary, { name, onError, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Plugin, {}) })
 465        },
 466        name
 467      )) });
 468    }
 469    var plugin_area_default = PluginArea;
 470    return __toCommonJS(index_exports);
 471  })();
 472  /*! Bundled license information:
 473  
 474  react-is/cjs/react-is.development.js:
 475    (**
 476     * @license React
 477     * react-is.development.js
 478     *
 479     * Copyright (c) Meta Platforms, Inc. and affiliates.
 480     *
 481     * This source code is licensed under the MIT license found in the
 482     * LICENSE file in the root directory of this source tree.
 483     *)
 484  */
 485  (window.wp ||= {}).plugins = wp.plugins;
 486  })();


Generated : Mon Nov 2 08:20:36 2026 Cross-referenced by PHPXref