[ 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),
  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  ;// ./node_modules/memize/dist/index.js
  64  /**
  65   * Memize options object.
  66   *
  67   * @typedef MemizeOptions
  68   *
  69   * @property {number} [maxSize] Maximum size of the cache.
  70   */
  71  
  72  /**
  73   * Internal cache entry.
  74   *
  75   * @typedef MemizeCacheNode
  76   *
  77   * @property {?MemizeCacheNode|undefined} [prev] Previous node.
  78   * @property {?MemizeCacheNode|undefined} [next] Next node.
  79   * @property {Array<*>}                   args   Function arguments for cache
  80   *                                               entry.
  81   * @property {*}                          val    Function result.
  82   */
  83  
  84  /**
  85   * Properties of the enhanced function for controlling cache.
  86   *
  87   * @typedef MemizeMemoizedFunction
  88   *
  89   * @property {()=>void} clear Clear the cache.
  90   */
  91  
  92  /**
  93   * Accepts a function to be memoized, and returns a new memoized function, with
  94   * optional options.
  95   *
  96   * @template {(...args: any[]) => any} F
  97   *
  98   * @param {F}             fn        Function to memoize.
  99   * @param {MemizeOptions} [options] Options object.
 100   *
 101   * @return {((...args: Parameters<F>) => ReturnType<F>) & MemizeMemoizedFunction} Memoized function.
 102   */
 103  function memize(fn, options) {
 104      var size = 0;
 105  
 106      /** @type {?MemizeCacheNode|undefined} */
 107      var head;
 108  
 109      /** @type {?MemizeCacheNode|undefined} */
 110      var tail;
 111  
 112      options = options || {};
 113  
 114  	function memoized(/* ...args */) {
 115          var node = head,
 116              len = arguments.length,
 117              args,
 118              i;
 119  
 120          searchCache: while (node) {
 121              // Perform a shallow equality test to confirm that whether the node
 122              // under test is a candidate for the arguments passed. Two arrays
 123              // are shallowly equal if their length matches and each entry is
 124              // strictly equal between the two sets. Avoid abstracting to a
 125              // function which could incur an arguments leaking deoptimization.
 126  
 127              // Check whether node arguments match arguments length
 128              if (node.args.length !== arguments.length) {
 129                  node = node.next;
 130                  continue;
 131              }
 132  
 133              // Check whether node arguments match arguments values
 134              for (i = 0; i < len; i++) {
 135                  if (node.args[i] !== arguments[i]) {
 136                      node = node.next;
 137                      continue searchCache;
 138                  }
 139              }
 140  
 141              // At this point we can assume we've found a match
 142  
 143              // Surface matched node to head if not already
 144              if (node !== head) {
 145                  // As tail, shift to previous. Must only shift if not also
 146                  // head, since if both head and tail, there is no previous.
 147                  if (node === tail) {
 148                      tail = node.prev;
 149                  }
 150  
 151                  // Adjust siblings to point to each other. If node was tail,
 152                  // this also handles new tail's empty `next` assignment.
 153                  /** @type {MemizeCacheNode} */ (node.prev).next = node.next;
 154                  if (node.next) {
 155                      node.next.prev = node.prev;
 156                  }
 157  
 158                  node.next = head;
 159                  node.prev = null;
 160                  /** @type {MemizeCacheNode} */ (head).prev = node;
 161                  head = node;
 162              }
 163  
 164              // Return immediately
 165              return node.val;
 166          }
 167  
 168          // No cached value found. Continue to insertion phase:
 169  
 170          // Create a copy of arguments (avoid leaking deoptimization)
 171          args = new Array(len);
 172          for (i = 0; i < len; i++) {
 173              args[i] = arguments[i];
 174          }
 175  
 176          node = {
 177              args: args,
 178  
 179              // Generate the result from original function
 180              val: fn.apply(null, args),
 181          };
 182  
 183          // Don't need to check whether node is already head, since it would
 184          // have been returned above already if it was
 185  
 186          // Shift existing head down list
 187          if (head) {
 188              head.prev = node;
 189              node.next = head;
 190          } else {
 191              // If no head, follows that there's no tail (at initial or reset)
 192              tail = node;
 193          }
 194  
 195          // Trim tail if we're reached max size and are pending cache insertion
 196          if (size === /** @type {MemizeOptions} */ (options).maxSize) {
 197              tail = /** @type {MemizeCacheNode} */ (tail).prev;
 198              /** @type {MemizeCacheNode} */ (tail).next = null;
 199          } else {
 200              size++;
 201          }
 202  
 203          head = node;
 204  
 205          return node.val;
 206      }
 207  
 208      memoized.clear = function () {
 209          head = null;
 210          tail = null;
 211          size = 0;
 212      };
 213  
 214      // Ignore reason: There's not a clear solution to create an intersection of
 215      // the function with additional properties, where the goal is to retain the
 216      // function signature of the incoming argument and add control properties
 217      // on the return value.
 218  
 219      // @ts-ignore
 220      return memoized;
 221  }
 222  
 223  
 224  
 225  ;// external ["wp","element"]
 226  const external_wp_element_namespaceObject = window["wp"]["element"];
 227  ;// external ["wp","hooks"]
 228  const external_wp_hooks_namespaceObject = window["wp"]["hooks"];
 229  ;// external ["wp","isShallowEqual"]
 230  const external_wp_isShallowEqual_namespaceObject = window["wp"]["isShallowEqual"];
 231  var external_wp_isShallowEqual_default = /*#__PURE__*/__webpack_require__.n(external_wp_isShallowEqual_namespaceObject);
 232  ;// external ["wp","compose"]
 233  const external_wp_compose_namespaceObject = window["wp"]["compose"];
 234  ;// external ["wp","deprecated"]
 235  const external_wp_deprecated_namespaceObject = window["wp"]["deprecated"];
 236  var external_wp_deprecated_default = /*#__PURE__*/__webpack_require__.n(external_wp_deprecated_namespaceObject);
 237  ;// external "ReactJSXRuntime"
 238  const external_ReactJSXRuntime_namespaceObject = window["ReactJSXRuntime"];
 239  ;// ./node_modules/@wordpress/plugins/build-module/components/plugin-context/index.js
 240  /**
 241   * WordPress dependencies
 242   */
 243  
 244  
 245  
 246  
 247  /**
 248   * Internal dependencies
 249   */
 250  
 251  const Context = (0,external_wp_element_namespaceObject.createContext)({
 252    name: null,
 253    icon: null
 254  });
 255  const PluginContextProvider = Context.Provider;
 256  
 257  /**
 258   * A hook that returns the plugin context.
 259   *
 260   * @return {PluginContext} Plugin context
 261   */
 262  function usePluginContext() {
 263    return (0,external_wp_element_namespaceObject.useContext)(Context);
 264  }
 265  
 266  /**
 267   * A Higher Order Component used to inject Plugin context to the
 268   * wrapped component.
 269   *
 270   * @deprecated 6.8.0 Use `usePluginContext` hook instead.
 271   *
 272   * @param  mapContextToProps Function called on every context change,
 273   *                           expected to return object of props to
 274   *                           merge with the component's own props.
 275   *
 276   * @return {Component} Enhanced component with injected context as props.
 277   */
 278  const withPluginContext = mapContextToProps => (0,external_wp_compose_namespaceObject.createHigherOrderComponent)(OriginalComponent => {
 279    external_wp_deprecated_default()('wp.plugins.withPluginContext', {
 280      since: '6.8.0',
 281      alternative: 'wp.plugins.usePluginContext'
 282    });
 283    return props => /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(Context.Consumer, {
 284      children: context => /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(OriginalComponent, {
 285        ...props,
 286        ...mapContextToProps(context, props)
 287      })
 288    });
 289  }, 'withPluginContext');
 290  
 291  ;// ./node_modules/@wordpress/plugins/build-module/components/plugin-error-boundary/index.js
 292  /**
 293   * WordPress dependencies
 294   */
 295  
 296  class PluginErrorBoundary extends external_wp_element_namespaceObject.Component {
 297    /**
 298     * @param {Object} props
 299     */
 300    constructor(props) {
 301      super(props);
 302      this.state = {
 303        hasError: false
 304      };
 305    }
 306    static getDerivedStateFromError() {
 307      return {
 308        hasError: true
 309      };
 310    }
 311  
 312    /**
 313     * @param {Error} error Error object passed by React.
 314     */
 315    componentDidCatch(error) {
 316      const {
 317        name,
 318        onError
 319      } = this.props;
 320      if (onError) {
 321        onError(name, error);
 322      }
 323    }
 324    render() {
 325      if (!this.state.hasError) {
 326        return this.props.children;
 327      }
 328      return null;
 329    }
 330  }
 331  
 332  ;// external ["wp","primitives"]
 333  const external_wp_primitives_namespaceObject = window["wp"]["primitives"];
 334  ;// ./node_modules/@wordpress/icons/build-module/library/plugins.js
 335  /**
 336   * WordPress dependencies
 337   */
 338  
 339  
 340  const plugins = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
 341    xmlns: "http://www.w3.org/2000/svg",
 342    viewBox: "0 0 24 24",
 343    children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
 344      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"
 345    })
 346  });
 347  /* harmony default export */ const library_plugins = (plugins);
 348  
 349  ;// ./node_modules/@wordpress/plugins/build-module/api/index.js
 350  /* wp:polyfill */
 351  /* eslint no-console: [ 'error', { allow: [ 'error' ] } ] */
 352  /**
 353   * External dependencies
 354   */
 355  
 356  /**
 357   * WordPress dependencies
 358   */
 359  
 360  
 361  
 362  /**
 363   * Defined behavior of a plugin type.
 364   */
 365  
 366  /**
 367   * Plugin definitions keyed by plugin name.
 368   */
 369  const api_plugins = {};
 370  
 371  /**
 372   * Registers a plugin to the editor.
 373   *
 374   * @param name     A string identifying the plugin. Must be
 375   *                 unique across all registered plugins.
 376   * @param settings The settings for this plugin.
 377   *
 378   * @example
 379   * ```js
 380   * // Using ES5 syntax
 381   * var el = React.createElement;
 382   * var Fragment = wp.element.Fragment;
 383   * var PluginSidebar = wp.editor.PluginSidebar;
 384   * var PluginSidebarMoreMenuItem = wp.editor.PluginSidebarMoreMenuItem;
 385   * var registerPlugin = wp.plugins.registerPlugin;
 386   * var moreIcon = React.createElement( 'svg' ); //... svg element.
 387   *
 388   * function Component() {
 389   *     return el(
 390   *         Fragment,
 391   *         {},
 392   *         el(
 393   *             PluginSidebarMoreMenuItem,
 394   *             {
 395   *                 target: 'sidebar-name',
 396   *             },
 397   *             'My Sidebar'
 398   *         ),
 399   *         el(
 400   *             PluginSidebar,
 401   *             {
 402   *                 name: 'sidebar-name',
 403   *                 title: 'My Sidebar',
 404   *             },
 405   *             'Content of the sidebar'
 406   *         )
 407   *     );
 408   * }
 409   * registerPlugin( 'plugin-name', {
 410   *     icon: moreIcon,
 411   *     render: Component,
 412   *     scope: 'my-page',
 413   * } );
 414   * ```
 415   *
 416   * @example
 417   * ```js
 418   * // Using ESNext syntax
 419   * import { PluginSidebar, PluginSidebarMoreMenuItem } from '@wordpress/editor';
 420   * import { registerPlugin } from '@wordpress/plugins';
 421   * import { more } from '@wordpress/icons';
 422   *
 423   * const Component = () => (
 424   *     <>
 425   *         <PluginSidebarMoreMenuItem
 426   *             target="sidebar-name"
 427   *         >
 428   *             My Sidebar
 429   *         </PluginSidebarMoreMenuItem>
 430   *         <PluginSidebar
 431   *             name="sidebar-name"
 432   *             title="My Sidebar"
 433   *         >
 434   *             Content of the sidebar
 435   *         </PluginSidebar>
 436   *     </>
 437   * );
 438   *
 439   * registerPlugin( 'plugin-name', {
 440   *     icon: more,
 441   *     render: Component,
 442   *     scope: 'my-page',
 443   * } );
 444   * ```
 445   *
 446   * @return The final plugin settings object.
 447   */
 448  function registerPlugin(name, settings) {
 449    if (typeof settings !== 'object') {
 450      console.error('No settings object provided!');
 451      return null;
 452    }
 453    if (typeof name !== 'string') {
 454      console.error('Plugin name must be string.');
 455      return null;
 456    }
 457    if (!/^[a-z][a-z0-9-]*$/.test(name)) {
 458      console.error('Plugin name must include only lowercase alphanumeric characters or dashes, and start with a letter. Example: "my-plugin".');
 459      return null;
 460    }
 461    if (api_plugins[name]) {
 462      console.error(`Plugin "$name}" is already registered.`);
 463    }
 464    settings = (0,external_wp_hooks_namespaceObject.applyFilters)('plugins.registerPlugin', settings, name);
 465    const {
 466      render,
 467      scope
 468    } = settings;
 469    if (typeof render !== 'function') {
 470      console.error('The "render" property must be specified and must be a valid function.');
 471      return null;
 472    }
 473    if (scope) {
 474      if (typeof scope !== 'string') {
 475        console.error('Plugin scope must be string.');
 476        return null;
 477      }
 478      if (!/^[a-z][a-z0-9-]*$/.test(scope)) {
 479        console.error('Plugin scope must include only lowercase alphanumeric characters or dashes, and start with a letter. Example: "my-page".');
 480        return null;
 481      }
 482    }
 483    api_plugins[name] = {
 484      name,
 485      icon: library_plugins,
 486      ...settings
 487    };
 488    (0,external_wp_hooks_namespaceObject.doAction)('plugins.pluginRegistered', settings, name);
 489    return settings;
 490  }
 491  
 492  /**
 493   * Unregisters a plugin by name.
 494   *
 495   * @param name Plugin name.
 496   *
 497   * @example
 498   * ```js
 499   * // Using ES5 syntax
 500   * var unregisterPlugin = wp.plugins.unregisterPlugin;
 501   *
 502   * unregisterPlugin( 'plugin-name' );
 503   * ```
 504   *
 505   * @example
 506   * ```js
 507   * // Using ESNext syntax
 508   * import { unregisterPlugin } from '@wordpress/plugins';
 509   *
 510   * unregisterPlugin( 'plugin-name' );
 511   * ```
 512   *
 513   * @return The previous plugin settings object, if it has been
 514   *         successfully unregistered; otherwise `undefined`.
 515   */
 516  function unregisterPlugin(name) {
 517    if (!api_plugins[name]) {
 518      console.error('Plugin "' + name + '" is not registered.');
 519      return;
 520    }
 521    const oldPlugin = api_plugins[name];
 522    delete api_plugins[name];
 523    (0,external_wp_hooks_namespaceObject.doAction)('plugins.pluginUnregistered', oldPlugin, name);
 524    return oldPlugin;
 525  }
 526  
 527  /**
 528   * Returns a registered plugin settings.
 529   *
 530   * @param name Plugin name.
 531   *
 532   * @return Plugin setting.
 533   */
 534  function getPlugin(name) {
 535    return api_plugins[name];
 536  }
 537  
 538  /**
 539   * Returns all registered plugins without a scope or for a given scope.
 540   *
 541   * @param scope The scope to be used when rendering inside
 542   *              a plugin area. No scope by default.
 543   *
 544   * @return The list of plugins without a scope or for a given scope.
 545   */
 546  function getPlugins(scope) {
 547    return Object.values(api_plugins).filter(plugin => plugin.scope === scope);
 548  }
 549  
 550  ;// ./node_modules/@wordpress/plugins/build-module/components/plugin-area/index.js
 551  /* wp:polyfill */
 552  /**
 553   * External dependencies
 554   */
 555  
 556  
 557  /**
 558   * WordPress dependencies
 559   */
 560  
 561  
 562  
 563  
 564  /**
 565   * Internal dependencies
 566   */
 567  
 568  
 569  
 570  
 571  const getPluginContext = memize((icon, name) => ({
 572    icon,
 573    name
 574  }));
 575  
 576  /**
 577   * A component that renders all plugin fills in a hidden div.
 578   *
 579   * @param  props
 580   * @param  props.scope
 581   * @param  props.onError
 582   * @example
 583   * ```js
 584   * // Using ES5 syntax
 585   * var el = React.createElement;
 586   * var PluginArea = wp.plugins.PluginArea;
 587   *
 588   * function Layout() {
 589   *     return el(
 590   *         'div',
 591   *         { scope: 'my-page' },
 592   *         'Content of the page',
 593   *         PluginArea
 594   *     );
 595   * }
 596   * ```
 597   *
 598   * @example
 599   * ```js
 600   * // Using ESNext syntax
 601   * import { PluginArea } from '@wordpress/plugins';
 602   *
 603   * const Layout = () => (
 604   *     <div>
 605   *         Content of the page
 606   *         <PluginArea scope="my-page" />
 607   *     </div>
 608   * );
 609   * ```
 610   *
 611   * @return {Component} The component to be rendered.
 612   */
 613  function PluginArea({
 614    scope,
 615    onError
 616  }) {
 617    const store = (0,external_wp_element_namespaceObject.useMemo)(() => {
 618      let lastValue = [];
 619      return {
 620        subscribe(listener) {
 621          (0,external_wp_hooks_namespaceObject.addAction)('plugins.pluginRegistered', 'core/plugins/plugin-area/plugins-registered', listener);
 622          (0,external_wp_hooks_namespaceObject.addAction)('plugins.pluginUnregistered', 'core/plugins/plugin-area/plugins-unregistered', listener);
 623          return () => {
 624            (0,external_wp_hooks_namespaceObject.removeAction)('plugins.pluginRegistered', 'core/plugins/plugin-area/plugins-registered');
 625            (0,external_wp_hooks_namespaceObject.removeAction)('plugins.pluginUnregistered', 'core/plugins/plugin-area/plugins-unregistered');
 626          };
 627        },
 628        getValue() {
 629          const nextValue = getPlugins(scope);
 630          if (!external_wp_isShallowEqual_default()(lastValue, nextValue)) {
 631            lastValue = nextValue;
 632          }
 633          return lastValue;
 634        }
 635      };
 636    }, [scope]);
 637    const plugins = (0,external_wp_element_namespaceObject.useSyncExternalStore)(store.subscribe, store.getValue, store.getValue);
 638    return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", {
 639      style: {
 640        display: 'none'
 641      },
 642      children: plugins.map(({
 643        icon,
 644        name,
 645        render: Plugin
 646      }) => /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(PluginContextProvider, {
 647        value: getPluginContext(icon, name),
 648        children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(PluginErrorBoundary, {
 649          name: name,
 650          onError: onError,
 651          children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(Plugin, {})
 652        })
 653      }, name))
 654    });
 655  }
 656  /* harmony default export */ const plugin_area = (PluginArea);
 657  
 658  ;// ./node_modules/@wordpress/plugins/build-module/components/index.js
 659  
 660  
 661  
 662  ;// ./node_modules/@wordpress/plugins/build-module/index.js
 663  
 664  
 665  
 666  (window.wp = window.wp || {}).plugins = __webpack_exports__;
 667  /******/ })()
 668  ;


Generated : Sat Feb 22 08:20:01 2025 Cross-referenced by PHPXref