[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

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

   1  /******/ (() => { // webpackBootstrap
   2  /******/     "use strict";
   3  /******/     // The require scope
   4  /******/     var __webpack_require__ = {};
   5  /******/     
   6  /************************************************************************/
   7  /******/     /* webpack/runtime/compat get default export */
   8  /******/     (() => {
   9  /******/         // getDefaultExport function for compatibility with non-harmony modules
  10  /******/         __webpack_require__.n = (module) => {
  11  /******/             var getter = module && module.__esModule ?
  12  /******/                 () => (module['default']) :
  13  /******/                 () => (module);
  14  /******/             __webpack_require__.d(getter, { a: getter });
  15  /******/             return getter;
  16  /******/         };
  17  /******/     })();
  18  /******/     
  19  /******/     /* webpack/runtime/define property getters */
  20  /******/     (() => {
  21  /******/         // define getter functions for harmony exports
  22  /******/         __webpack_require__.d = (exports, definition) => {
  23  /******/             for(var key in definition) {
  24  /******/                 if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  25  /******/                     Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  26  /******/                 }
  27  /******/             }
  28  /******/         };
  29  /******/     })();
  30  /******/     
  31  /******/     /* webpack/runtime/hasOwnProperty shorthand */
  32  /******/     (() => {
  33  /******/         __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
  34  /******/     })();
  35  /******/     
  36  /******/     /* webpack/runtime/make namespace object */
  37  /******/     (() => {
  38  /******/         // define __esModule on exports
  39  /******/         __webpack_require__.r = (exports) => {
  40  /******/             if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  41  /******/                 Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  42  /******/             }
  43  /******/             Object.defineProperty(exports, '__esModule', { value: true });
  44  /******/         };
  45  /******/     })();
  46  /******/     
  47  /************************************************************************/
  48  var __webpack_exports__ = {};
  49  // ESM COMPAT FLAG
  50  __webpack_require__.r(__webpack_exports__);
  51  
  52  // EXPORTS
  53  __webpack_require__.d(__webpack_exports__, {
  54    PluginArea: () => (/* reexport */ plugin_area_default),
  55    getPlugin: () => (/* reexport */ getPlugin),
  56    getPlugins: () => (/* reexport */ getPlugins),
  57    registerPlugin: () => (/* reexport */ registerPlugin),
  58    unregisterPlugin: () => (/* reexport */ unregisterPlugin),
  59    usePluginContext: () => (/* reexport */ usePluginContext),
  60    withPluginContext: () => (/* reexport */ withPluginContext)
  61  });
  62  
  63  ;// external "ReactJSXRuntime"
  64  const external_ReactJSXRuntime_namespaceObject = window["ReactJSXRuntime"];
  65  ;// ./node_modules/memize/dist/index.js
  66  /**
  67   * Memize options object.
  68   *
  69   * @typedef MemizeOptions
  70   *
  71   * @property {number} [maxSize] Maximum size of the cache.
  72   */
  73  
  74  /**
  75   * Internal cache entry.
  76   *
  77   * @typedef MemizeCacheNode
  78   *
  79   * @property {?MemizeCacheNode|undefined} [prev] Previous node.
  80   * @property {?MemizeCacheNode|undefined} [next] Next node.
  81   * @property {Array<*>}                   args   Function arguments for cache
  82   *                                               entry.
  83   * @property {*}                          val    Function result.
  84   */
  85  
  86  /**
  87   * Properties of the enhanced function for controlling cache.
  88   *
  89   * @typedef MemizeMemoizedFunction
  90   *
  91   * @property {()=>void} clear Clear the cache.
  92   */
  93  
  94  /**
  95   * Accepts a function to be memoized, and returns a new memoized function, with
  96   * optional options.
  97   *
  98   * @template {(...args: any[]) => any} F
  99   *
 100   * @param {F}             fn        Function to memoize.
 101   * @param {MemizeOptions} [options] Options object.
 102   *
 103   * @return {((...args: Parameters<F>) => ReturnType<F>) & MemizeMemoizedFunction} Memoized function.
 104   */
 105  function memize(fn, options) {
 106      var size = 0;
 107  
 108      /** @type {?MemizeCacheNode|undefined} */
 109      var head;
 110  
 111      /** @type {?MemizeCacheNode|undefined} */
 112      var tail;
 113  
 114      options = options || {};
 115  
 116  	function memoized(/* ...args */) {
 117          var node = head,
 118              len = arguments.length,
 119              args,
 120              i;
 121  
 122          searchCache: while (node) {
 123              // Perform a shallow equality test to confirm that whether the node
 124              // under test is a candidate for the arguments passed. Two arrays
 125              // are shallowly equal if their length matches and each entry is
 126              // strictly equal between the two sets. Avoid abstracting to a
 127              // function which could incur an arguments leaking deoptimization.
 128  
 129              // Check whether node arguments match arguments length
 130              if (node.args.length !== arguments.length) {
 131                  node = node.next;
 132                  continue;
 133              }
 134  
 135              // Check whether node arguments match arguments values
 136              for (i = 0; i < len; i++) {
 137                  if (node.args[i] !== arguments[i]) {
 138                      node = node.next;
 139                      continue searchCache;
 140                  }
 141              }
 142  
 143              // At this point we can assume we've found a match
 144  
 145              // Surface matched node to head if not already
 146              if (node !== head) {
 147                  // As tail, shift to previous. Must only shift if not also
 148                  // head, since if both head and tail, there is no previous.
 149                  if (node === tail) {
 150                      tail = node.prev;
 151                  }
 152  
 153                  // Adjust siblings to point to each other. If node was tail,
 154                  // this also handles new tail's empty `next` assignment.
 155                  /** @type {MemizeCacheNode} */ (node.prev).next = node.next;
 156                  if (node.next) {
 157                      node.next.prev = node.prev;
 158                  }
 159  
 160                  node.next = head;
 161                  node.prev = null;
 162                  /** @type {MemizeCacheNode} */ (head).prev = node;
 163                  head = node;
 164              }
 165  
 166              // Return immediately
 167              return node.val;
 168          }
 169  
 170          // No cached value found. Continue to insertion phase:
 171  
 172          // Create a copy of arguments (avoid leaking deoptimization)
 173          args = new Array(len);
 174          for (i = 0; i < len; i++) {
 175              args[i] = arguments[i];
 176          }
 177  
 178          node = {
 179              args: args,
 180  
 181              // Generate the result from original function
 182              val: fn.apply(null, args),
 183          };
 184  
 185          // Don't need to check whether node is already head, since it would
 186          // have been returned above already if it was
 187  
 188          // Shift existing head down list
 189          if (head) {
 190              head.prev = node;
 191              node.next = head;
 192          } else {
 193              // If no head, follows that there's no tail (at initial or reset)
 194              tail = node;
 195          }
 196  
 197          // Trim tail if we're reached max size and are pending cache insertion
 198          if (size === /** @type {MemizeOptions} */ (options).maxSize) {
 199              tail = /** @type {MemizeCacheNode} */ (tail).prev;
 200              /** @type {MemizeCacheNode} */ (tail).next = null;
 201          } else {
 202              size++;
 203          }
 204  
 205          head = node;
 206  
 207          return node.val;
 208      }
 209  
 210      memoized.clear = function () {
 211          head = null;
 212          tail = null;
 213          size = 0;
 214      };
 215  
 216      // Ignore reason: There's not a clear solution to create an intersection of
 217      // the function with additional properties, where the goal is to retain the
 218      // function signature of the incoming argument and add control properties
 219      // on the return value.
 220  
 221      // @ts-ignore
 222      return memoized;
 223  }
 224  
 225  
 226  
 227  ;// external ["wp","element"]
 228  const external_wp_element_namespaceObject = window["wp"]["element"];
 229  ;// external ["wp","hooks"]
 230  const external_wp_hooks_namespaceObject = window["wp"]["hooks"];
 231  ;// external ["wp","isShallowEqual"]
 232  const external_wp_isShallowEqual_namespaceObject = window["wp"]["isShallowEqual"];
 233  var external_wp_isShallowEqual_default = /*#__PURE__*/__webpack_require__.n(external_wp_isShallowEqual_namespaceObject);
 234  ;// external ["wp","compose"]
 235  const external_wp_compose_namespaceObject = window["wp"]["compose"];
 236  ;// external ["wp","deprecated"]
 237  const external_wp_deprecated_namespaceObject = window["wp"]["deprecated"];
 238  var external_wp_deprecated_default = /*#__PURE__*/__webpack_require__.n(external_wp_deprecated_namespaceObject);
 239  ;// ./node_modules/@wordpress/plugins/build-module/components/plugin-context/index.js
 240  
 241  
 242  
 243  
 244  const Context = (0,external_wp_element_namespaceObject.createContext)({
 245    name: null,
 246    icon: null
 247  });
 248  Context.displayName = "PluginContext";
 249  const PluginContextProvider = Context.Provider;
 250  function usePluginContext() {
 251    return (0,external_wp_element_namespaceObject.useContext)(Context);
 252  }
 253  const withPluginContext = (mapContextToProps) => (0,external_wp_compose_namespaceObject.createHigherOrderComponent)((OriginalComponent) => {
 254    external_wp_deprecated_default()("wp.plugins.withPluginContext", {
 255      since: "6.8.0",
 256      alternative: "wp.plugins.usePluginContext"
 257    });
 258    return (props) => /* @__PURE__ */ (0,external_ReactJSXRuntime_namespaceObject.jsx)(Context.Consumer, { children: (context) => /* @__PURE__ */ (0,external_ReactJSXRuntime_namespaceObject.jsx)(
 259      OriginalComponent,
 260      {
 261        ...props,
 262        ...mapContextToProps(context, props)
 263      }
 264    ) });
 265  }, "withPluginContext");
 266  
 267  
 268  ;// ./node_modules/@wordpress/plugins/build-module/components/plugin-error-boundary/index.js
 269  
 270  class PluginErrorBoundary extends external_wp_element_namespaceObject.Component {
 271    constructor(props) {
 272      super(props);
 273      this.state = {
 274        hasError: false
 275      };
 276    }
 277    static getDerivedStateFromError() {
 278      return { hasError: true };
 279    }
 280    componentDidCatch(error) {
 281      const { name, onError } = this.props;
 282      if (onError) {
 283        onError(name, error);
 284      }
 285    }
 286    render() {
 287      if (!this.state.hasError) {
 288        return this.props.children;
 289      }
 290      return null;
 291    }
 292  }
 293  
 294  
 295  ;// external ["wp","primitives"]
 296  const external_wp_primitives_namespaceObject = window["wp"]["primitives"];
 297  ;// ./node_modules/@wordpress/icons/build-module/library/plugins.js
 298  
 299  
 300  var plugins_default = /* @__PURE__ */ (0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.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" }) });
 301  
 302  
 303  ;// ./node_modules/@wordpress/plugins/build-module/api/index.js
 304  
 305  
 306  const plugins = {};
 307  function registerPlugin(name, settings) {
 308    if (typeof settings !== "object") {
 309      console.error("No settings object provided!");
 310      return null;
 311    }
 312    if (typeof name !== "string") {
 313      console.error("Plugin name must be string.");
 314      return null;
 315    }
 316    if (!/^[a-z][a-z0-9-]*$/.test(name)) {
 317      console.error(
 318        'Plugin name must include only lowercase alphanumeric characters or dashes, and start with a letter. Example: "my-plugin".'
 319      );
 320      return null;
 321    }
 322    if (plugins[name]) {
 323      console.error(`Plugin "$name}" is already registered.`);
 324    }
 325    settings = (0,external_wp_hooks_namespaceObject.applyFilters)(
 326      "plugins.registerPlugin",
 327      settings,
 328      name
 329    );
 330    const { render, scope } = settings;
 331    if (typeof render !== "function") {
 332      console.error(
 333        'The "render" property must be specified and must be a valid function.'
 334      );
 335      return null;
 336    }
 337    if (scope) {
 338      if (typeof scope !== "string") {
 339        console.error("Plugin scope must be string.");
 340        return null;
 341      }
 342      if (!/^[a-z][a-z0-9-]*$/.test(scope)) {
 343        console.error(
 344          'Plugin scope must include only lowercase alphanumeric characters or dashes, and start with a letter. Example: "my-page".'
 345        );
 346        return null;
 347      }
 348    }
 349    plugins[name] = {
 350      name,
 351      icon: plugins_default,
 352      ...settings
 353    };
 354    (0,external_wp_hooks_namespaceObject.doAction)("plugins.pluginRegistered", settings, name);
 355    return settings;
 356  }
 357  function unregisterPlugin(name) {
 358    if (!plugins[name]) {
 359      console.error('Plugin "' + name + '" is not registered.');
 360      return;
 361    }
 362    const oldPlugin = plugins[name];
 363    delete plugins[name];
 364    (0,external_wp_hooks_namespaceObject.doAction)("plugins.pluginUnregistered", oldPlugin, name);
 365    return oldPlugin;
 366  }
 367  function getPlugin(name) {
 368    return plugins[name];
 369  }
 370  function getPlugins(scope) {
 371    return Object.values(plugins).filter(
 372      (plugin) => plugin.scope === scope
 373    );
 374  }
 375  
 376  
 377  ;// ./node_modules/@wordpress/plugins/build-module/components/plugin-area/index.js
 378  
 379  
 380  
 381  
 382  
 383  
 384  
 385  
 386  const getPluginContext = memize(
 387    (icon, name) => ({
 388      icon,
 389      name
 390    })
 391  );
 392  function PluginArea({
 393    scope,
 394    onError
 395  }) {
 396    const store = (0,external_wp_element_namespaceObject.useMemo)(() => {
 397      let lastValue = [];
 398      return {
 399        subscribe(listener) {
 400          (0,external_wp_hooks_namespaceObject.addAction)(
 401            "plugins.pluginRegistered",
 402            "core/plugins/plugin-area/plugins-registered",
 403            listener
 404          );
 405          (0,external_wp_hooks_namespaceObject.addAction)(
 406            "plugins.pluginUnregistered",
 407            "core/plugins/plugin-area/plugins-unregistered",
 408            listener
 409          );
 410          return () => {
 411            (0,external_wp_hooks_namespaceObject.removeAction)(
 412              "plugins.pluginRegistered",
 413              "core/plugins/plugin-area/plugins-registered"
 414            );
 415            (0,external_wp_hooks_namespaceObject.removeAction)(
 416              "plugins.pluginUnregistered",
 417              "core/plugins/plugin-area/plugins-unregistered"
 418            );
 419          };
 420        },
 421        getValue() {
 422          const nextValue = getPlugins(scope);
 423          if (!external_wp_isShallowEqual_default()(lastValue, nextValue)) {
 424            lastValue = nextValue;
 425          }
 426          return lastValue;
 427        }
 428      };
 429    }, [scope]);
 430    const plugins = (0,external_wp_element_namespaceObject.useSyncExternalStore)(
 431      store.subscribe,
 432      store.getValue,
 433      store.getValue
 434    );
 435    return /* @__PURE__ */ (0,external_ReactJSXRuntime_namespaceObject.jsx)("div", { style: { display: "none" }, children: plugins.map(({ icon, name, render: Plugin }) => /* @__PURE__ */ (0,external_ReactJSXRuntime_namespaceObject.jsx)(
 436      PluginContextProvider,
 437      {
 438        value: getPluginContext(icon, name),
 439        children: /* @__PURE__ */ (0,external_ReactJSXRuntime_namespaceObject.jsx)(PluginErrorBoundary, { name, onError, children: /* @__PURE__ */ (0,external_ReactJSXRuntime_namespaceObject.jsx)(Plugin, {}) })
 440      },
 441      name
 442    )) });
 443  }
 444  var plugin_area_default = PluginArea;
 445  
 446  
 447  ;// ./node_modules/@wordpress/plugins/build-module/components/index.js
 448  
 449  
 450  
 451  
 452  ;// ./node_modules/@wordpress/plugins/build-module/index.js
 453  
 454  
 455  
 456  (window.wp = window.wp || {}).plugins = __webpack_exports__;
 457  /******/ })()
 458  ;


Generated : Wed Oct 22 08:20:04 2025 Cross-referenced by PHPXref