[ 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    // packages/plugins/node_modules/react-is/cjs/react-is.development.js
  79    var require_react_is_development = __commonJS({
  80      "packages/plugins/node_modules/react-is/cjs/react-is.development.js"(exports) {
  81        "use strict";
  82        if (true) {
  83          (function() {
  84            "use strict";
  85            var REACT_ELEMENT_TYPE = /* @__PURE__ */ Symbol.for("react.element");
  86            var REACT_PORTAL_TYPE = /* @__PURE__ */ Symbol.for("react.portal");
  87            var REACT_FRAGMENT_TYPE = /* @__PURE__ */ Symbol.for("react.fragment");
  88            var REACT_STRICT_MODE_TYPE = /* @__PURE__ */ Symbol.for("react.strict_mode");
  89            var REACT_PROFILER_TYPE = /* @__PURE__ */ Symbol.for("react.profiler");
  90            var REACT_PROVIDER_TYPE = /* @__PURE__ */ Symbol.for("react.provider");
  91            var REACT_CONTEXT_TYPE = /* @__PURE__ */ Symbol.for("react.context");
  92            var REACT_SERVER_CONTEXT_TYPE = /* @__PURE__ */ Symbol.for("react.server_context");
  93            var REACT_FORWARD_REF_TYPE = /* @__PURE__ */ Symbol.for("react.forward_ref");
  94            var REACT_SUSPENSE_TYPE = /* @__PURE__ */ Symbol.for("react.suspense");
  95            var REACT_SUSPENSE_LIST_TYPE = /* @__PURE__ */ Symbol.for("react.suspense_list");
  96            var REACT_MEMO_TYPE = /* @__PURE__ */ Symbol.for("react.memo");
  97            var REACT_LAZY_TYPE = /* @__PURE__ */ Symbol.for("react.lazy");
  98            var REACT_OFFSCREEN_TYPE = /* @__PURE__ */ Symbol.for("react.offscreen");
  99            var enableScopeAPI = false;
 100            var enableCacheElement = false;
 101            var enableTransitionTracing = false;
 102            var enableLegacyHidden = false;
 103            var enableDebugTracing = false;
 104            var REACT_MODULE_REFERENCE;
 105            {
 106              REACT_MODULE_REFERENCE = /* @__PURE__ */ Symbol.for("react.module.reference");
 107            }
 108            function isValidElementType2(type) {
 109              if (typeof type === "string" || typeof type === "function") {
 110                return true;
 111              }
 112              if (type === REACT_FRAGMENT_TYPE || type === REACT_PROFILER_TYPE || enableDebugTracing || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_TYPE || enableLegacyHidden || type === REACT_OFFSCREEN_TYPE || enableScopeAPI || enableCacheElement || enableTransitionTracing) {
 113                return true;
 114              }
 115              if (typeof type === "object" && type !== null) {
 116                if (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE || // This needs to include all possible module reference object
 117                // types supported by any Flight configuration anywhere since
 118                // we don't know which Flight build this will end up being used
 119                // with.
 120                type.$$typeof === REACT_MODULE_REFERENCE || type.getModuleId !== void 0) {
 121                  return true;
 122                }
 123              }
 124              return false;
 125            }
 126            function typeOf(object) {
 127              if (typeof object === "object" && object !== null) {
 128                var $$typeof = object.$$typeof;
 129                switch ($$typeof) {
 130                  case REACT_ELEMENT_TYPE:
 131                    var type = object.type;
 132                    switch (type) {
 133                      case REACT_FRAGMENT_TYPE:
 134                      case REACT_PROFILER_TYPE:
 135                      case REACT_STRICT_MODE_TYPE:
 136                      case REACT_SUSPENSE_TYPE:
 137                      case REACT_SUSPENSE_LIST_TYPE:
 138                        return type;
 139                      default:
 140                        var $$typeofType = type && type.$$typeof;
 141                        switch ($$typeofType) {
 142                          case REACT_SERVER_CONTEXT_TYPE:
 143                          case REACT_CONTEXT_TYPE:
 144                          case REACT_FORWARD_REF_TYPE:
 145                          case REACT_LAZY_TYPE:
 146                          case REACT_MEMO_TYPE:
 147                          case REACT_PROVIDER_TYPE:
 148                            return $$typeofType;
 149                          default:
 150                            return $$typeof;
 151                        }
 152                    }
 153                  case REACT_PORTAL_TYPE:
 154                    return $$typeof;
 155                }
 156              }
 157              return void 0;
 158            }
 159            var ContextConsumer = REACT_CONTEXT_TYPE;
 160            var ContextProvider = REACT_PROVIDER_TYPE;
 161            var Element = REACT_ELEMENT_TYPE;
 162            var ForwardRef = REACT_FORWARD_REF_TYPE;
 163            var Fragment = REACT_FRAGMENT_TYPE;
 164            var Lazy = REACT_LAZY_TYPE;
 165            var Memo = REACT_MEMO_TYPE;
 166            var Portal = REACT_PORTAL_TYPE;
 167            var Profiler = REACT_PROFILER_TYPE;
 168            var StrictMode = REACT_STRICT_MODE_TYPE;
 169            var Suspense = REACT_SUSPENSE_TYPE;
 170            var SuspenseList = REACT_SUSPENSE_LIST_TYPE;
 171            var hasWarnedAboutDeprecatedIsAsyncMode = false;
 172            var hasWarnedAboutDeprecatedIsConcurrentMode = false;
 173            function isAsyncMode(object) {
 174              {
 175                if (!hasWarnedAboutDeprecatedIsAsyncMode) {
 176                  hasWarnedAboutDeprecatedIsAsyncMode = true;
 177                  console["warn"]("The ReactIs.isAsyncMode() alias has been deprecated, and will be removed in React 18+.");
 178                }
 179              }
 180              return false;
 181            }
 182            function isConcurrentMode(object) {
 183              {
 184                if (!hasWarnedAboutDeprecatedIsConcurrentMode) {
 185                  hasWarnedAboutDeprecatedIsConcurrentMode = true;
 186                  console["warn"]("The ReactIs.isConcurrentMode() alias has been deprecated, and will be removed in React 18+.");
 187                }
 188              }
 189              return false;
 190            }
 191            function isContextConsumer(object) {
 192              return typeOf(object) === REACT_CONTEXT_TYPE;
 193            }
 194            function isContextProvider(object) {
 195              return typeOf(object) === REACT_PROVIDER_TYPE;
 196            }
 197            function isElement(object) {
 198              return typeof object === "object" && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
 199            }
 200            function isForwardRef(object) {
 201              return typeOf(object) === REACT_FORWARD_REF_TYPE;
 202            }
 203            function isFragment(object) {
 204              return typeOf(object) === REACT_FRAGMENT_TYPE;
 205            }
 206            function isLazy(object) {
 207              return typeOf(object) === REACT_LAZY_TYPE;
 208            }
 209            function isMemo(object) {
 210              return typeOf(object) === REACT_MEMO_TYPE;
 211            }
 212            function isPortal(object) {
 213              return typeOf(object) === REACT_PORTAL_TYPE;
 214            }
 215            function isProfiler(object) {
 216              return typeOf(object) === REACT_PROFILER_TYPE;
 217            }
 218            function isStrictMode(object) {
 219              return typeOf(object) === REACT_STRICT_MODE_TYPE;
 220            }
 221            function isSuspense(object) {
 222              return typeOf(object) === REACT_SUSPENSE_TYPE;
 223            }
 224            function isSuspenseList(object) {
 225              return typeOf(object) === REACT_SUSPENSE_LIST_TYPE;
 226            }
 227            exports.ContextConsumer = ContextConsumer;
 228            exports.ContextProvider = ContextProvider;
 229            exports.Element = Element;
 230            exports.ForwardRef = ForwardRef;
 231            exports.Fragment = Fragment;
 232            exports.Lazy = Lazy;
 233            exports.Memo = Memo;
 234            exports.Portal = Portal;
 235            exports.Profiler = Profiler;
 236            exports.StrictMode = StrictMode;
 237            exports.Suspense = Suspense;
 238            exports.SuspenseList = SuspenseList;
 239            exports.isAsyncMode = isAsyncMode;
 240            exports.isConcurrentMode = isConcurrentMode;
 241            exports.isContextConsumer = isContextConsumer;
 242            exports.isContextProvider = isContextProvider;
 243            exports.isElement = isElement;
 244            exports.isForwardRef = isForwardRef;
 245            exports.isFragment = isFragment;
 246            exports.isLazy = isLazy;
 247            exports.isMemo = isMemo;
 248            exports.isPortal = isPortal;
 249            exports.isProfiler = isProfiler;
 250            exports.isStrictMode = isStrictMode;
 251            exports.isSuspense = isSuspense;
 252            exports.isSuspenseList = isSuspenseList;
 253            exports.isValidElementType = isValidElementType2;
 254            exports.typeOf = typeOf;
 255          })();
 256        }
 257      }
 258    });
 259  
 260    // packages/plugins/node_modules/react-is/index.js
 261    var require_react_is = __commonJS({
 262      "packages/plugins/node_modules/react-is/index.js"(exports, module) {
 263        "use strict";
 264        if (false) {
 265          module.exports = null;
 266        } else {
 267          module.exports = require_react_is_development();
 268        }
 269      }
 270    });
 271  
 272    // package-external:@wordpress/primitives
 273    var require_primitives = __commonJS({
 274      "package-external:@wordpress/primitives"(exports, module) {
 275        module.exports = window.wp.primitives;
 276      }
 277    });
 278  
 279    // packages/plugins/build-module/index.mjs
 280    var index_exports = {};
 281    __export(index_exports, {
 282      PluginArea: () => plugin_area_default,
 283      getPlugin: () => getPlugin,
 284      getPlugins: () => getPlugins,
 285      registerPlugin: () => registerPlugin,
 286      unregisterPlugin: () => unregisterPlugin,
 287      usePluginContext: () => usePluginContext,
 288      withPluginContext: () => withPluginContext
 289    });
 290  
 291    // node_modules/memize/dist/index.js
 292    function memize(fn, options) {
 293      var size = 0;
 294      var head;
 295      var tail;
 296      options = options || {};
 297      function memoized() {
 298        var node = head, len = arguments.length, args, i;
 299        searchCache: while (node) {
 300          if (node.args.length !== arguments.length) {
 301            node = node.next;
 302            continue;
 303          }
 304          for (i = 0; i < len; i++) {
 305            if (node.args[i] !== arguments[i]) {
 306              node = node.next;
 307              continue searchCache;
 308            }
 309          }
 310          if (node !== head) {
 311            if (node === tail) {
 312              tail = node.prev;
 313            }
 314            node.prev.next = node.next;
 315            if (node.next) {
 316              node.next.prev = node.prev;
 317            }
 318            node.next = head;
 319            node.prev = null;
 320            head.prev = node;
 321            head = node;
 322          }
 323          return node.val;
 324        }
 325        args = new Array(len);
 326        for (i = 0; i < len; i++) {
 327          args[i] = arguments[i];
 328        }
 329        node = {
 330          args,
 331          // Generate the result from original function
 332          val: fn.apply(null, args)
 333        };
 334        if (head) {
 335          head.prev = node;
 336          node.next = head;
 337        } else {
 338          tail = node;
 339        }
 340        if (size === /** @type {MemizeOptions} */
 341        options.maxSize) {
 342          tail = /** @type {MemizeCacheNode} */
 343          tail.prev;
 344          tail.next = null;
 345        } else {
 346          size++;
 347        }
 348        head = node;
 349        return node.val;
 350      }
 351      memoized.clear = function() {
 352        head = null;
 353        tail = null;
 354        size = 0;
 355      };
 356      return memoized;
 357    }
 358  
 359    // packages/plugins/build-module/components/plugin-area/index.mjs
 360    var import_element3 = __toESM(require_element(), 1);
 361    var import_hooks2 = __toESM(require_hooks(), 1);
 362    var import_is_shallow_equal = __toESM(require_is_shallow_equal(), 1);
 363  
 364    // packages/plugins/build-module/components/plugin-context/index.mjs
 365    var import_element = __toESM(require_element(), 1);
 366    var import_compose = __toESM(require_compose(), 1);
 367    var import_deprecated = __toESM(require_deprecated(), 1);
 368    var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
 369    var Context = (0, import_element.createContext)({
 370      name: null,
 371      icon: null
 372    });
 373    Context.displayName = "PluginContext";
 374    var PluginContextProvider = Context.Provider;
 375    function usePluginContext() {
 376      return (0, import_element.useContext)(Context);
 377    }
 378    var withPluginContext = (mapContextToProps) => (0, import_compose.createHigherOrderComponent)((OriginalComponent) => {
 379      (0, import_deprecated.default)("wp.plugins.withPluginContext", {
 380        since: "6.8.0",
 381        alternative: "wp.plugins.usePluginContext"
 382      });
 383      return (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Context.Consumer, { children: (context) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
 384        OriginalComponent,
 385        {
 386          ...props,
 387          ...mapContextToProps(context, props)
 388        }
 389      ) });
 390    }, "withPluginContext");
 391  
 392    // packages/plugins/build-module/components/plugin-error-boundary/index.mjs
 393    var import_element2 = __toESM(require_element(), 1);
 394    var PluginErrorBoundary = class extends import_element2.Component {
 395      constructor(props) {
 396        super(props);
 397        this.state = {
 398          hasError: false
 399        };
 400      }
 401      static getDerivedStateFromError() {
 402        return { hasError: true };
 403      }
 404      componentDidCatch(error) {
 405        const { name, onError } = this.props;
 406        if (onError) {
 407          onError(name, error);
 408        }
 409      }
 410      render() {
 411        if (!this.state.hasError) {
 412          return this.props.children;
 413        }
 414        return null;
 415      }
 416    };
 417  
 418    // packages/plugins/build-module/api/index.mjs
 419    var import_react_is = __toESM(require_react_is(), 1);
 420    var import_hooks = __toESM(require_hooks(), 1);
 421  
 422    // packages/icons/build-module/library/plugins.mjs
 423    var import_primitives = __toESM(require_primitives(), 1);
 424    var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
 425    var plugins_default = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_primitives.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_primitives.Path, { d: "M10.5 4v4h3V4H15v4h1.5a1 1 0 011 1v4l-3 4v2a1 1 0 01-1 1h-3a1 1 0 01-1-1v-2l-3-4V9a1 1 0 011-1H9V4h1.5zm.5 12.5v2h2v-2l3-4v-3H8v3l3 4z" }) });
 426  
 427    // packages/plugins/build-module/api/index.mjs
 428    var plugins = {};
 429    function registerPlugin(name, settings) {
 430      if (typeof settings !== "object") {
 431        console.error("No settings object provided!");
 432        return null;
 433      }
 434      if (typeof name !== "string") {
 435        console.error("Plugin name must be string.");
 436        return null;
 437      }
 438      if (!/^[a-z][a-z0-9-]*$/.test(name)) {
 439        console.error(
 440          'Plugin name must include only lowercase alphanumeric characters or dashes, and start with a letter. Example: "my-plugin".'
 441        );
 442        return null;
 443      }
 444      if (plugins[name]) {
 445        console.error(`Plugin "$name}" is already registered.`);
 446      }
 447      settings = (0, import_hooks.applyFilters)(
 448        "plugins.registerPlugin",
 449        settings,
 450        name
 451      );
 452      const { render, scope } = settings;
 453      if (!(0, import_react_is.isValidElementType)(render)) {
 454        console.error(
 455          'The "render" property must be specified and must be a valid component.'
 456        );
 457        return null;
 458      }
 459      if (scope) {
 460        if (typeof scope !== "string") {
 461          console.error("Plugin scope must be string.");
 462          return null;
 463        }
 464        if (!/^[a-z][a-z0-9-]*$/.test(scope)) {
 465          console.error(
 466            'Plugin scope must include only lowercase alphanumeric characters or dashes, and start with a letter. Example: "my-page".'
 467          );
 468          return null;
 469        }
 470      }
 471      plugins[name] = {
 472        name,
 473        icon: plugins_default,
 474        ...settings
 475      };
 476      (0, import_hooks.doAction)("plugins.pluginRegistered", settings, name);
 477      return settings;
 478    }
 479    function unregisterPlugin(name) {
 480      if (!plugins[name]) {
 481        console.error('Plugin "' + name + '" is not registered.');
 482        return;
 483      }
 484      const oldPlugin = plugins[name];
 485      delete plugins[name];
 486      (0, import_hooks.doAction)("plugins.pluginUnregistered", oldPlugin, name);
 487      return oldPlugin;
 488    }
 489    function getPlugin(name) {
 490      return plugins[name];
 491    }
 492    function getPlugins(scope) {
 493      return Object.values(plugins).filter(
 494        (plugin) => plugin.scope === scope
 495      );
 496    }
 497  
 498    // packages/plugins/build-module/components/plugin-area/index.mjs
 499    var import_jsx_runtime3 = __toESM(require_jsx_runtime(), 1);
 500    var getPluginContext = memize(
 501      (icon, name) => ({
 502        icon,
 503        name
 504      })
 505    );
 506    function PluginArea({
 507      scope,
 508      onError
 509    }) {
 510      const store = (0, import_element3.useMemo)(() => {
 511        let lastValue = [];
 512        return {
 513          subscribe(listener) {
 514            (0, import_hooks2.addAction)(
 515              "plugins.pluginRegistered",
 516              "core/plugins/plugin-area/plugins-registered",
 517              listener
 518            );
 519            (0, import_hooks2.addAction)(
 520              "plugins.pluginUnregistered",
 521              "core/plugins/plugin-area/plugins-unregistered",
 522              listener
 523            );
 524            return () => {
 525              (0, import_hooks2.removeAction)(
 526                "plugins.pluginRegistered",
 527                "core/plugins/plugin-area/plugins-registered"
 528              );
 529              (0, import_hooks2.removeAction)(
 530                "plugins.pluginUnregistered",
 531                "core/plugins/plugin-area/plugins-unregistered"
 532              );
 533            };
 534          },
 535          getValue() {
 536            const nextValue = getPlugins(scope);
 537            if (!(0, import_is_shallow_equal.isShallowEqual)(lastValue, nextValue)) {
 538              lastValue = nextValue;
 539            }
 540            return lastValue;
 541          }
 542        };
 543      }, [scope]);
 544      const plugins2 = (0, import_element3.useSyncExternalStore)(
 545        store.subscribe,
 546        store.getValue,
 547        store.getValue
 548      );
 549      return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { display: "none" }, children: plugins2.map(({ icon, name, render: Plugin }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
 550        PluginContextProvider,
 551        {
 552          value: getPluginContext(icon, name),
 553          children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(PluginErrorBoundary, { name, onError, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Plugin, {}) })
 554        },
 555        name
 556      )) });
 557    }
 558    var plugin_area_default = PluginArea;
 559    return __toCommonJS(index_exports);
 560  })();
 561  /*! Bundled license information:
 562  
 563  react-is/cjs/react-is.development.js:
 564    (**
 565     * @license React
 566     * react-is.development.js
 567     *
 568     * Copyright (c) Facebook, Inc. and its affiliates.
 569     *
 570     * This source code is licensed under the MIT license found in the
 571     * LICENSE file in the root directory of this source tree.
 572     *)
 573  */
 574  (window.wp ||= {}).plugins = wp.plugins;
 575  })();


Generated : Mon Aug 10 08:20:22 2026 Cross-referenced by PHPXref