[ 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  ;// CONCATENATED MODULE: ./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  ;// CONCATENATED MODULE: external ["wp","element"]
 226  const external_wp_element_namespaceObject = window["wp"]["element"];
 227  ;// CONCATENATED MODULE: external ["wp","hooks"]
 228  const external_wp_hooks_namespaceObject = window["wp"]["hooks"];
 229  ;// CONCATENATED MODULE: 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  ;// CONCATENATED MODULE: external ["wp","compose"]
 233  const external_wp_compose_namespaceObject = window["wp"]["compose"];
 234  ;// CONCATENATED MODULE: external "ReactJSXRuntime"
 235  const external_ReactJSXRuntime_namespaceObject = window["ReactJSXRuntime"];
 236  ;// CONCATENATED MODULE: ./node_modules/@wordpress/plugins/build-module/components/plugin-context/index.js
 237  /**
 238   * WordPress dependencies
 239   */
 240  
 241  
 242  
 243  /**
 244   * Internal dependencies
 245   */
 246  
 247  const Context = (0,external_wp_element_namespaceObject.createContext)({
 248    name: null,
 249    icon: null
 250  });
 251  const PluginContextProvider = Context.Provider;
 252  
 253  /**
 254   * A hook that returns the plugin context.
 255   *
 256   * @return {PluginContext} Plugin context
 257   */
 258  function usePluginContext() {
 259    return (0,external_wp_element_namespaceObject.useContext)(Context);
 260  }
 261  
 262  /**
 263   * A Higher Order Component used to inject Plugin context to the
 264   * wrapped component.
 265   *
 266   * @param  mapContextToProps Function called on every context change,
 267   *                           expected to return object of props to
 268   *                           merge with the component's own props.
 269   *
 270   * @return {Component} Enhanced component with injected context as props.
 271   */
 272  const withPluginContext = mapContextToProps => (0,external_wp_compose_namespaceObject.createHigherOrderComponent)(OriginalComponent => {
 273    return props => /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(Context.Consumer, {
 274      children: context => /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(OriginalComponent, {
 275        ...props,
 276        ...mapContextToProps(context, props)
 277      })
 278    });
 279  }, 'withPluginContext');
 280  
 281  ;// CONCATENATED MODULE: ./node_modules/@wordpress/plugins/build-module/components/plugin-error-boundary/index.js
 282  /**
 283   * WordPress dependencies
 284   */
 285  
 286  class PluginErrorBoundary extends external_wp_element_namespaceObject.Component {
 287    /**
 288     * @param {Object} props
 289     */
 290    constructor(props) {
 291      super(props);
 292      this.state = {
 293        hasError: false
 294      };
 295    }
 296    static getDerivedStateFromError() {
 297      return {
 298        hasError: true
 299      };
 300    }
 301  
 302    /**
 303     * @param {Error} error Error object passed by React.
 304     */
 305    componentDidCatch(error) {
 306      const {
 307        name,
 308        onError
 309      } = this.props;
 310      if (onError) {
 311        onError(name, error);
 312      }
 313    }
 314    render() {
 315      if (!this.state.hasError) {
 316        return this.props.children;
 317      }
 318      return null;
 319    }
 320  }
 321  
 322  ;// CONCATENATED MODULE: external ["wp","primitives"]
 323  const external_wp_primitives_namespaceObject = window["wp"]["primitives"];
 324  ;// CONCATENATED MODULE: ./node_modules/@wordpress/icons/build-module/library/plugins.js
 325  /**
 326   * WordPress dependencies
 327   */
 328  
 329  
 330  const plugins = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
 331    xmlns: "http://www.w3.org/2000/svg",
 332    viewBox: "0 0 24 24",
 333    children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
 334      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"
 335    })
 336  });
 337  /* harmony default export */ const library_plugins = (plugins);
 338  
 339  ;// CONCATENATED MODULE: ./node_modules/@wordpress/plugins/build-module/api/index.js
 340  /* eslint no-console: [ 'error', { allow: [ 'error' ] } ] */
 341  /**
 342   * External dependencies
 343   */
 344  
 345  /**
 346   * WordPress dependencies
 347   */
 348  
 349  
 350  
 351  /**
 352   * Defined behavior of a plugin type.
 353   */
 354  
 355  /**
 356   * Plugin definitions keyed by plugin name.
 357   */
 358  const api_plugins = {};
 359  
 360  /**
 361   * Registers a plugin to the editor.
 362   *
 363   * @param name     A string identifying the plugin. Must be
 364   *                 unique across all registered plugins.
 365   * @param settings The settings for this plugin.
 366   *
 367   * @example
 368   * ```js
 369   * // Using ES5 syntax
 370   * var el = React.createElement;
 371   * var Fragment = wp.element.Fragment;
 372   * var PluginSidebar = wp.editor.PluginSidebar;
 373   * var PluginSidebarMoreMenuItem = wp.editor.PluginSidebarMoreMenuItem;
 374   * var registerPlugin = wp.plugins.registerPlugin;
 375   * var moreIcon = React.createElement( 'svg' ); //... svg element.
 376   *
 377   * function Component() {
 378   *     return el(
 379   *         Fragment,
 380   *         {},
 381   *         el(
 382   *             PluginSidebarMoreMenuItem,
 383   *             {
 384   *                 target: 'sidebar-name',
 385   *             },
 386   *             'My Sidebar'
 387   *         ),
 388   *         el(
 389   *             PluginSidebar,
 390   *             {
 391   *                 name: 'sidebar-name',
 392   *                 title: 'My Sidebar',
 393   *             },
 394   *             'Content of the sidebar'
 395   *         )
 396   *     );
 397   * }
 398   * registerPlugin( 'plugin-name', {
 399   *     icon: moreIcon,
 400   *     render: Component,
 401   *     scope: 'my-page',
 402   * } );
 403   * ```
 404   *
 405   * @example
 406   * ```js
 407   * // Using ESNext syntax
 408   * import { PluginSidebar, PluginSidebarMoreMenuItem } from '@wordpress/editor';
 409   * import { registerPlugin } from '@wordpress/plugins';
 410   * import { more } from '@wordpress/icons';
 411   *
 412   * const Component = () => (
 413   *     <>
 414   *         <PluginSidebarMoreMenuItem
 415   *             target="sidebar-name"
 416   *         >
 417   *             My Sidebar
 418   *         </PluginSidebarMoreMenuItem>
 419   *         <PluginSidebar
 420   *             name="sidebar-name"
 421   *             title="My Sidebar"
 422   *         >
 423   *             Content of the sidebar
 424   *         </PluginSidebar>
 425   *     </>
 426   * );
 427   *
 428   * registerPlugin( 'plugin-name', {
 429   *     icon: more,
 430   *     render: Component,
 431   *     scope: 'my-page',
 432   * } );
 433   * ```
 434   *
 435   * @return The final plugin settings object.
 436   */
 437  function registerPlugin(name, settings) {
 438    if (typeof settings !== 'object') {
 439      console.error('No settings object provided!');
 440      return null;
 441    }
 442    if (typeof name !== 'string') {
 443      console.error('Plugin name must be string.');
 444      return null;
 445    }
 446    if (!/^[a-z][a-z0-9-]*$/.test(name)) {
 447      console.error('Plugin name must include only lowercase alphanumeric characters or dashes, and start with a letter. Example: "my-plugin".');
 448      return null;
 449    }
 450    if (api_plugins[name]) {
 451      console.error(`Plugin "$name}" is already registered.`);
 452    }
 453    settings = (0,external_wp_hooks_namespaceObject.applyFilters)('plugins.registerPlugin', settings, name);
 454    const {
 455      render,
 456      scope
 457    } = settings;
 458    if (typeof render !== 'function') {
 459      console.error('The "render" property must be specified and must be a valid function.');
 460      return null;
 461    }
 462    if (scope) {
 463      if (typeof scope !== 'string') {
 464        console.error('Plugin scope must be string.');
 465        return null;
 466      }
 467      if (!/^[a-z][a-z0-9-]*$/.test(scope)) {
 468        console.error('Plugin scope must include only lowercase alphanumeric characters or dashes, and start with a letter. Example: "my-page".');
 469        return null;
 470      }
 471    }
 472    api_plugins[name] = {
 473      name,
 474      icon: library_plugins,
 475      ...settings
 476    };
 477    (0,external_wp_hooks_namespaceObject.doAction)('plugins.pluginRegistered', settings, name);
 478    return settings;
 479  }
 480  
 481  /**
 482   * Unregisters a plugin by name.
 483   *
 484   * @param name Plugin name.
 485   *
 486   * @example
 487   * ```js
 488   * // Using ES5 syntax
 489   * var unregisterPlugin = wp.plugins.unregisterPlugin;
 490   *
 491   * unregisterPlugin( 'plugin-name' );
 492   * ```
 493   *
 494   * @example
 495   * ```js
 496   * // Using ESNext syntax
 497   * import { unregisterPlugin } from '@wordpress/plugins';
 498   *
 499   * unregisterPlugin( 'plugin-name' );
 500   * ```
 501   *
 502   * @return The previous plugin settings object, if it has been
 503   *         successfully unregistered; otherwise `undefined`.
 504   */
 505  function unregisterPlugin(name) {
 506    if (!api_plugins[name]) {
 507      console.error('Plugin "' + name + '" is not registered.');
 508      return;
 509    }
 510    const oldPlugin = api_plugins[name];
 511    delete api_plugins[name];
 512    (0,external_wp_hooks_namespaceObject.doAction)('plugins.pluginUnregistered', oldPlugin, name);
 513    return oldPlugin;
 514  }
 515  
 516  /**
 517   * Returns a registered plugin settings.
 518   *
 519   * @param name Plugin name.
 520   *
 521   * @return Plugin setting.
 522   */
 523  function getPlugin(name) {
 524    return api_plugins[name];
 525  }
 526  
 527  /**
 528   * Returns all registered plugins without a scope or for a given scope.
 529   *
 530   * @param scope The scope to be used when rendering inside
 531   *              a plugin area. No scope by default.
 532   *
 533   * @return The list of plugins without a scope or for a given scope.
 534   */
 535  function getPlugins(scope) {
 536    return Object.values(api_plugins).filter(plugin => plugin.scope === scope);
 537  }
 538  
 539  ;// CONCATENATED MODULE: ./node_modules/@wordpress/plugins/build-module/components/plugin-area/index.js
 540  /**
 541   * External dependencies
 542   */
 543  
 544  
 545  /**
 546   * WordPress dependencies
 547   */
 548  
 549  
 550  
 551  
 552  /**
 553   * Internal dependencies
 554   */
 555  
 556  
 557  
 558  
 559  const getPluginContext = memize((icon, name) => ({
 560    icon,
 561    name
 562  }));
 563  
 564  /**
 565   * A component that renders all plugin fills in a hidden div.
 566   *
 567   * @param  props
 568   * @param  props.scope
 569   * @param  props.onError
 570   * @example
 571   * ```js
 572   * // Using ES5 syntax
 573   * var el = React.createElement;
 574   * var PluginArea = wp.plugins.PluginArea;
 575   *
 576   * function Layout() {
 577   *     return el(
 578   *         'div',
 579   *         { scope: 'my-page' },
 580   *         'Content of the page',
 581   *         PluginArea
 582   *     );
 583   * }
 584   * ```
 585   *
 586   * @example
 587   * ```js
 588   * // Using ESNext syntax
 589   * import { PluginArea } from '@wordpress/plugins';
 590   *
 591   * const Layout = () => (
 592   *     <div>
 593   *         Content of the page
 594   *         <PluginArea scope="my-page" />
 595   *     </div>
 596   * );
 597   * ```
 598   *
 599   * @return {Component} The component to be rendered.
 600   */
 601  function PluginArea({
 602    scope,
 603    onError
 604  }) {
 605    const store = (0,external_wp_element_namespaceObject.useMemo)(() => {
 606      let lastValue = [];
 607      return {
 608        subscribe(listener) {
 609          (0,external_wp_hooks_namespaceObject.addAction)('plugins.pluginRegistered', 'core/plugins/plugin-area/plugins-registered', listener);
 610          (0,external_wp_hooks_namespaceObject.addAction)('plugins.pluginUnregistered', 'core/plugins/plugin-area/plugins-unregistered', listener);
 611          return () => {
 612            (0,external_wp_hooks_namespaceObject.removeAction)('plugins.pluginRegistered', 'core/plugins/plugin-area/plugins-registered');
 613            (0,external_wp_hooks_namespaceObject.removeAction)('plugins.pluginUnregistered', 'core/plugins/plugin-area/plugins-unregistered');
 614          };
 615        },
 616        getValue() {
 617          const nextValue = getPlugins(scope);
 618          if (!external_wp_isShallowEqual_default()(lastValue, nextValue)) {
 619            lastValue = nextValue;
 620          }
 621          return lastValue;
 622        }
 623      };
 624    }, [scope]);
 625    const plugins = (0,external_wp_element_namespaceObject.useSyncExternalStore)(store.subscribe, store.getValue, store.getValue);
 626    return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", {
 627      style: {
 628        display: 'none'
 629      },
 630      children: plugins.map(({
 631        icon,
 632        name,
 633        render: Plugin
 634      }) => /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(PluginContextProvider, {
 635        value: getPluginContext(icon, name),
 636        children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(PluginErrorBoundary, {
 637          name: name,
 638          onError: onError,
 639          children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(Plugin, {})
 640        })
 641      }, name))
 642    });
 643  }
 644  /* harmony default export */ const plugin_area = (PluginArea);
 645  
 646  ;// CONCATENATED MODULE: ./node_modules/@wordpress/plugins/build-module/components/index.js
 647  
 648  
 649  
 650  ;// CONCATENATED MODULE: ./node_modules/@wordpress/plugins/build-module/index.js
 651  
 652  
 653  
 654  (window.wp = window.wp || {}).plugins = __webpack_exports__;
 655  /******/ })()
 656  ;


Generated : Thu Nov 21 08:20:01 2024 Cross-referenced by PHPXref