[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/js/dist/ -> reusable-blocks.js (source)

   1  this["wp"] = this["wp"] || {}; this["wp"]["reusableBlocks"] =
   2  /******/ (function(modules) { // webpackBootstrap
   3  /******/     // The module cache
   4  /******/     var installedModules = {};
   5  /******/
   6  /******/     // The require function
   7  /******/ 	function __webpack_require__(moduleId) {
   8  /******/
   9  /******/         // Check if module is in cache
  10  /******/         if(installedModules[moduleId]) {
  11  /******/             return installedModules[moduleId].exports;
  12  /******/         }
  13  /******/         // Create a new module (and put it into the cache)
  14  /******/         var module = installedModules[moduleId] = {
  15  /******/             i: moduleId,
  16  /******/             l: false,
  17  /******/             exports: {}
  18  /******/         };
  19  /******/
  20  /******/         // Execute the module function
  21  /******/         modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  22  /******/
  23  /******/         // Flag the module as loaded
  24  /******/         module.l = true;
  25  /******/
  26  /******/         // Return the exports of the module
  27  /******/         return module.exports;
  28  /******/     }
  29  /******/
  30  /******/
  31  /******/     // expose the modules object (__webpack_modules__)
  32  /******/     __webpack_require__.m = modules;
  33  /******/
  34  /******/     // expose the module cache
  35  /******/     __webpack_require__.c = installedModules;
  36  /******/
  37  /******/     // define getter function for harmony exports
  38  /******/     __webpack_require__.d = function(exports, name, getter) {
  39  /******/         if(!__webpack_require__.o(exports, name)) {
  40  /******/             Object.defineProperty(exports, name, { enumerable: true, get: getter });
  41  /******/         }
  42  /******/     };
  43  /******/
  44  /******/     // define __esModule on exports
  45  /******/     __webpack_require__.r = function(exports) {
  46  /******/         if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  47  /******/             Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  48  /******/         }
  49  /******/         Object.defineProperty(exports, '__esModule', { value: true });
  50  /******/     };
  51  /******/
  52  /******/     // create a fake namespace object
  53  /******/     // mode & 1: value is a module id, require it
  54  /******/     // mode & 2: merge all properties of value into the ns
  55  /******/     // mode & 4: return value when already ns object
  56  /******/     // mode & 8|1: behave like require
  57  /******/     __webpack_require__.t = function(value, mode) {
  58  /******/         if(mode & 1) value = __webpack_require__(value);
  59  /******/         if(mode & 8) return value;
  60  /******/         if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  61  /******/         var ns = Object.create(null);
  62  /******/         __webpack_require__.r(ns);
  63  /******/         Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  64  /******/         if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  65  /******/         return ns;
  66  /******/     };
  67  /******/
  68  /******/     // getDefaultExport function for compatibility with non-harmony modules
  69  /******/     __webpack_require__.n = function(module) {
  70  /******/         var getter = module && module.__esModule ?
  71  /******/ 			function getDefault() { return module['default']; } :
  72  /******/ 			function getModuleExports() { return module; };
  73  /******/         __webpack_require__.d(getter, 'a', getter);
  74  /******/         return getter;
  75  /******/     };
  76  /******/
  77  /******/     // Object.prototype.hasOwnProperty.call
  78  /******/     __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  79  /******/
  80  /******/     // __webpack_public_path__
  81  /******/     __webpack_require__.p = "";
  82  /******/
  83  /******/
  84  /******/     // Load entry module and return exports
  85  /******/     return __webpack_require__(__webpack_require__.s = 471);
  86  /******/ })
  87  /************************************************************************/
  88  /******/ ({
  89  
  90  /***/ 0:
  91  /***/ (function(module, exports) {
  92  
  93  (function() { module.exports = this["wp"]["element"]; }());
  94  
  95  /***/ }),
  96  
  97  /***/ 1:
  98  /***/ (function(module, exports) {
  99  
 100  (function() { module.exports = this["wp"]["i18n"]; }());
 101  
 102  /***/ }),
 103  
 104  /***/ 11:
 105  /***/ (function(module, exports) {
 106  
 107  (function() { module.exports = this["wp"]["blocks"]; }());
 108  
 109  /***/ }),
 110  
 111  /***/ 20:
 112  /***/ (function(module, exports) {
 113  
 114  (function() { module.exports = this["regeneratorRuntime"]; }());
 115  
 116  /***/ }),
 117  
 118  /***/ 3:
 119  /***/ (function(module, exports) {
 120  
 121  (function() { module.exports = this["wp"]["components"]; }());
 122  
 123  /***/ }),
 124  
 125  /***/ 4:
 126  /***/ (function(module, exports) {
 127  
 128  (function() { module.exports = this["wp"]["data"]; }());
 129  
 130  /***/ }),
 131  
 132  /***/ 45:
 133  /***/ (function(module, __webpack_exports__, __webpack_require__) {
 134  
 135  "use strict";
 136  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _asyncToGenerator; });
 137  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
 138    try {
 139      var info = gen[key](arg);
 140      var value = info.value;
 141    } catch (error) {
 142      reject(error);
 143      return;
 144    }
 145  
 146    if (info.done) {
 147      resolve(value);
 148    } else {
 149      Promise.resolve(value).then(_next, _throw);
 150    }
 151  }
 152  
 153  function _asyncToGenerator(fn) {
 154    return function () {
 155      var self = this,
 156          args = arguments;
 157      return new Promise(function (resolve, reject) {
 158        var gen = fn.apply(self, args);
 159  
 160        function _next(value) {
 161          asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
 162        }
 163  
 164        function _throw(err) {
 165          asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
 166        }
 167  
 168        _next(undefined);
 169      });
 170    };
 171  }
 172  
 173  /***/ }),
 174  
 175  /***/ 471:
 176  /***/ (function(module, __webpack_exports__, __webpack_require__) {
 177  
 178  "use strict";
 179  // ESM COMPAT FLAG
 180  __webpack_require__.r(__webpack_exports__);
 181  
 182  // EXPORTS
 183  __webpack_require__.d(__webpack_exports__, "ReusableBlocksMenuItems", function() { return /* reexport */ reusable_blocks_menu_items; });
 184  
 185  // NAMESPACE OBJECT: ./node_modules/@wordpress/reusable-blocks/build-module/store/actions.js
 186  var actions_namespaceObject = {};
 187  __webpack_require__.r(actions_namespaceObject);
 188  __webpack_require__.d(actions_namespaceObject, "__experimentalConvertBlockToStatic", function() { return __experimentalConvertBlockToStatic; });
 189  __webpack_require__.d(actions_namespaceObject, "__experimentalConvertBlocksToReusable", function() { return __experimentalConvertBlocksToReusable; });
 190  __webpack_require__.d(actions_namespaceObject, "__experimentalDeleteReusableBlock", function() { return __experimentalDeleteReusableBlock; });
 191  __webpack_require__.d(actions_namespaceObject, "__experimentalSetEditingReusableBlock", function() { return __experimentalSetEditingReusableBlock; });
 192  
 193  // NAMESPACE OBJECT: ./node_modules/@wordpress/reusable-blocks/build-module/store/selectors.js
 194  var selectors_namespaceObject = {};
 195  __webpack_require__.r(selectors_namespaceObject);
 196  __webpack_require__.d(selectors_namespaceObject, "__experimentalIsEditingReusableBlock", function() { return __experimentalIsEditingReusableBlock; });
 197  
 198  // EXTERNAL MODULE: external {"this":["wp","blockEditor"]}
 199  var external_this_wp_blockEditor_ = __webpack_require__(6);
 200  
 201  // EXTERNAL MODULE: external {"this":["wp","coreData"]}
 202  var external_this_wp_coreData_ = __webpack_require__(83);
 203  
 204  // EXTERNAL MODULE: external {"this":["wp","notices"]}
 205  var external_this_wp_notices_ = __webpack_require__(92);
 206  
 207  // EXTERNAL MODULE: external {"this":["wp","data"]}
 208  var external_this_wp_data_ = __webpack_require__(4);
 209  
 210  // EXTERNAL MODULE: external {"this":"regeneratorRuntime"}
 211  var external_this_regeneratorRuntime_ = __webpack_require__(20);
 212  var external_this_regeneratorRuntime_default = /*#__PURE__*/__webpack_require__.n(external_this_regeneratorRuntime_);
 213  
 214  // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js
 215  var asyncToGenerator = __webpack_require__(45);
 216  
 217  // EXTERNAL MODULE: external {"this":["wp","blocks"]}
 218  var external_this_wp_blocks_ = __webpack_require__(11);
 219  
 220  // EXTERNAL MODULE: external {"this":["wp","i18n"]}
 221  var external_this_wp_i18n_ = __webpack_require__(1);
 222  
 223  // CONCATENATED MODULE: ./node_modules/@wordpress/reusable-blocks/build-module/store/controls.js
 224  
 225  
 226  
 227  /**
 228   * WordPress dependencies
 229   */
 230  
 231  
 232  
 233  /**
 234   * Convert a reusable block to a static block effect handler
 235   *
 236   * @param {string}  clientId Block ID.
 237   * @return {Object} control descriptor.
 238   */
 239  
 240  function convertBlockToStatic(clientId) {
 241    return {
 242      type: 'CONVERT_BLOCK_TO_STATIC',
 243      clientId: clientId
 244    };
 245  }
 246  /**
 247   * Convert a static block to a reusable block effect handler
 248   *
 249   * @param {Array}  clientIds Block IDs.
 250   * @return {Object} control descriptor.
 251   */
 252  
 253  function controls_convertBlocksToReusable(clientIds) {
 254    return {
 255      type: 'CONVERT_BLOCKS_TO_REUSABLE',
 256      clientIds: clientIds
 257    };
 258  }
 259  /**
 260   * Deletes a reusable block.
 261   *
 262   * @param {string} id Reusable block ID.
 263   * @return {Object} control descriptor.
 264   */
 265  
 266  function controls_deleteReusableBlock(id) {
 267    return {
 268      type: 'DELETE_REUSABLE_BLOCK',
 269      id: id
 270    };
 271  }
 272  var controls = {
 273    CONVERT_BLOCK_TO_STATIC: Object(external_this_wp_data_["createRegistryControl"])(function (registry) {
 274      return function (_ref) {
 275        var clientId = _ref.clientId;
 276        var oldBlock = registry.select('core/block-editor').getBlock(clientId);
 277        var reusableBlock = registry.select('core').getEditedEntityRecord('postType', 'wp_block', oldBlock.attributes.ref);
 278        var newBlocks = Object(external_this_wp_blocks_["parse"])(reusableBlock.content);
 279        registry.dispatch('core/block-editor').replaceBlocks(oldBlock.clientId, newBlocks);
 280      };
 281    }),
 282    CONVERT_BLOCKS_TO_REUSABLE: Object(external_this_wp_data_["createRegistryControl"])(function (registry) {
 283      return /*#__PURE__*/function () {
 284        var _ref3 = Object(asyncToGenerator["a" /* default */])( /*#__PURE__*/external_this_regeneratorRuntime_default.a.mark(function _callee(_ref2) {
 285          var clientIds, reusableBlock, updatedRecord, newBlock;
 286          return external_this_regeneratorRuntime_default.a.wrap(function _callee$(_context) {
 287            while (1) {
 288              switch (_context.prev = _context.next) {
 289                case 0:
 290                  clientIds = _ref2.clientIds;
 291                  reusableBlock = {
 292                    title: Object(external_this_wp_i18n_["__"])('Untitled Reusable Block'),
 293                    content: Object(external_this_wp_blocks_["serialize"])(registry.select('core/block-editor').getBlocksByClientId(clientIds)),
 294                    status: 'publish'
 295                  };
 296                  _context.next = 4;
 297                  return registry.dispatch('core').saveEntityRecord('postType', 'wp_block', reusableBlock);
 298  
 299                case 4:
 300                  updatedRecord = _context.sent;
 301                  newBlock = Object(external_this_wp_blocks_["createBlock"])('core/block', {
 302                    ref: updatedRecord.id
 303                  });
 304                  registry.dispatch('core/block-editor').replaceBlocks(clientIds, newBlock);
 305  
 306                  registry.dispatch('core/reusable-blocks').__experimentalSetEditingReusableBlock(newBlock.clientId, true);
 307  
 308                case 8:
 309                case "end":
 310                  return _context.stop();
 311              }
 312            }
 313          }, _callee);
 314        }));
 315  
 316        return function (_x) {
 317          return _ref3.apply(this, arguments);
 318        };
 319      }();
 320    }),
 321    DELETE_REUSABLE_BLOCK: Object(external_this_wp_data_["createRegistryControl"])(function (registry) {
 322      return /*#__PURE__*/function () {
 323        var _ref5 = Object(asyncToGenerator["a" /* default */])( /*#__PURE__*/external_this_regeneratorRuntime_default.a.mark(function _callee2(_ref4) {
 324          var id, reusableBlock, allBlocks, associatedBlocks, associatedBlockClientIds;
 325          return external_this_regeneratorRuntime_default.a.wrap(function _callee2$(_context2) {
 326            while (1) {
 327              switch (_context2.prev = _context2.next) {
 328                case 0:
 329                  id = _ref4.id;
 330                  reusableBlock = registry.select('core').getEditedEntityRecord('postType', 'wp_block', id); // Don't allow a reusable block with a temporary ID to be deleted
 331  
 332                  if (reusableBlock) {
 333                    _context2.next = 4;
 334                    break;
 335                  }
 336  
 337                  return _context2.abrupt("return");
 338  
 339                case 4:
 340                  // Remove any other blocks that reference this reusable block
 341                  allBlocks = registry.select('core/block-editor').getBlocks();
 342                  associatedBlocks = allBlocks.filter(function (block) {
 343                    return Object(external_this_wp_blocks_["isReusableBlock"])(block) && block.attributes.ref === id;
 344                  });
 345                  associatedBlockClientIds = associatedBlocks.map(function (block) {
 346                    return block.clientId;
 347                  }); // Remove the parsed block.
 348  
 349                  if (associatedBlockClientIds.length) {
 350                    registry.dispatch('core/block-editor').removeBlocks(associatedBlockClientIds);
 351                  }
 352  
 353                  _context2.next = 10;
 354                  return registry.dispatch('core').deleteEntityRecord('postType', 'wp_block', id);
 355  
 356                case 10:
 357                case "end":
 358                  return _context2.stop();
 359              }
 360            }
 361          }, _callee2);
 362        }));
 363  
 364        return function (_x2) {
 365          return _ref5.apply(this, arguments);
 366        };
 367      }();
 368    })
 369  };
 370  /* harmony default export */ var store_controls = (controls);
 371  
 372  // CONCATENATED MODULE: ./node_modules/@wordpress/reusable-blocks/build-module/store/actions.js
 373  
 374  
 375  var _marked = /*#__PURE__*/external_this_regeneratorRuntime_default.a.mark(__experimentalConvertBlockToStatic),
 376      _marked2 = /*#__PURE__*/external_this_regeneratorRuntime_default.a.mark(__experimentalConvertBlocksToReusable),
 377      _marked3 = /*#__PURE__*/external_this_regeneratorRuntime_default.a.mark(__experimentalDeleteReusableBlock);
 378  
 379  /**
 380   * Internal dependencies
 381   */
 382  
 383  /**
 384   * Returns a generator converting a reusable block into a static block.
 385   *
 386   * @param {string} clientId The client ID of the block to attach.
 387   */
 388  
 389  function __experimentalConvertBlockToStatic(clientId) {
 390    return external_this_regeneratorRuntime_default.a.wrap(function __experimentalConvertBlockToStatic$(_context) {
 391      while (1) {
 392        switch (_context.prev = _context.next) {
 393          case 0:
 394            _context.next = 2;
 395            return convertBlockToStatic(clientId);
 396  
 397          case 2:
 398          case "end":
 399            return _context.stop();
 400        }
 401      }
 402    }, _marked);
 403  }
 404  /**
 405   * Returns a generator converting one or more static blocks into a reusable block.
 406   *
 407   * @param {string[]} clientIds The client IDs of the block to detach.
 408   */
 409  
 410  function __experimentalConvertBlocksToReusable(clientIds) {
 411    return external_this_regeneratorRuntime_default.a.wrap(function __experimentalConvertBlocksToReusable$(_context2) {
 412      while (1) {
 413        switch (_context2.prev = _context2.next) {
 414          case 0:
 415            _context2.next = 2;
 416            return controls_convertBlocksToReusable(clientIds);
 417  
 418          case 2:
 419          case "end":
 420            return _context2.stop();
 421        }
 422      }
 423    }, _marked2);
 424  }
 425  /**
 426   * Returns a generator deleting a reusable block.
 427   *
 428   * @param {string} id The ID of the reusable block to delete.
 429   */
 430  
 431  function __experimentalDeleteReusableBlock(id) {
 432    return external_this_regeneratorRuntime_default.a.wrap(function __experimentalDeleteReusableBlock$(_context3) {
 433      while (1) {
 434        switch (_context3.prev = _context3.next) {
 435          case 0:
 436            _context3.next = 2;
 437            return controls_deleteReusableBlock(id);
 438  
 439          case 2:
 440          case "end":
 441            return _context3.stop();
 442        }
 443      }
 444    }, _marked3);
 445  }
 446  /**
 447   * Returns an action descriptor for SET_EDITING_REUSABLE_BLOCK action.
 448   *
 449   * @param {string} clientId The clientID of the reusable block to target.
 450   * @param {boolean} isEditing Whether the block should be in editing state.
 451   * @return {Object} Action descriptor.
 452   */
 453  
 454  function __experimentalSetEditingReusableBlock(clientId, isEditing) {
 455    return {
 456      type: 'SET_EDITING_REUSABLE_BLOCK',
 457      clientId: clientId,
 458      isEditing: isEditing
 459    };
 460  }
 461  
 462  // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/defineProperty.js
 463  var defineProperty = __webpack_require__(5);
 464  
 465  // CONCATENATED MODULE: ./node_modules/@wordpress/reusable-blocks/build-module/store/reducer.js
 466  
 467  
 468  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
 469  
 470  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { Object(defineProperty["a" /* default */])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
 471  
 472  /**
 473   * WordPress dependencies
 474   */
 475  
 476  function isEditingReusableBlock() {
 477    var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
 478    var action = arguments.length > 1 ? arguments[1] : undefined;
 479  
 480    if ((action === null || action === void 0 ? void 0 : action.type) === 'SET_EDITING_REUSABLE_BLOCK') {
 481      return _objectSpread(_objectSpread({}, state), {}, Object(defineProperty["a" /* default */])({}, action.clientId, action.isEditing));
 482    }
 483  
 484    return state;
 485  }
 486  /* harmony default export */ var reducer = (Object(external_this_wp_data_["combineReducers"])({
 487    isEditingReusableBlock: isEditingReusableBlock
 488  }));
 489  
 490  // CONCATENATED MODULE: ./node_modules/@wordpress/reusable-blocks/build-module/store/selectors.js
 491  /**
 492   * Returns true if reusable block is in the editing state.
 493   *
 494   * @param {Object} state Global application state.
 495   * @param {number} clientId the clientID of the block.
 496   * @return {boolean} Whether the reusable block is in the editing state.
 497   */
 498  function __experimentalIsEditingReusableBlock(state, clientId) {
 499    return state.isEditingReusableBlock[clientId];
 500  }
 501  
 502  // CONCATENATED MODULE: ./node_modules/@wordpress/reusable-blocks/build-module/store/constants.js
 503  /**
 504   * Constant for the store module (or reducer) key.
 505   *
 506   * @type {string}
 507   */
 508  var STORE_KEY = 'core/reusable-blocks';
 509  
 510  // CONCATENATED MODULE: ./node_modules/@wordpress/reusable-blocks/build-module/store/index.js
 511  /**
 512   * WordPress dependencies
 513   */
 514  
 515  /**
 516   * Internal dependencies
 517   */
 518  
 519  
 520  
 521  
 522  
 523  
 524  /**
 525   * Data store configuration.
 526   *
 527   * @see https://github.com/WordPress/gutenberg/blob/master/packages/data/README.md#registerStore
 528   *
 529   * @type {Object}
 530   */
 531  
 532  /* harmony default export */ var store = (Object(external_this_wp_data_["registerStore"])(STORE_KEY, {
 533    actions: actions_namespaceObject,
 534    controls: store_controls,
 535    reducer: reducer,
 536    selectors: selectors_namespaceObject
 537  }));
 538  
 539  // EXTERNAL MODULE: external {"this":["wp","element"]}
 540  var external_this_wp_element_ = __webpack_require__(0);
 541  
 542  // EXTERNAL MODULE: external {"this":["wp","components"]}
 543  var external_this_wp_components_ = __webpack_require__(3);
 544  
 545  // EXTERNAL MODULE: external {"this":["wp","primitives"]}
 546  var external_this_wp_primitives_ = __webpack_require__(7);
 547  
 548  // CONCATENATED MODULE: ./node_modules/@wordpress/icons/build-module/library/reusable-block.js
 549  
 550  
 551  /**
 552   * WordPress dependencies
 553   */
 554  
 555  var reusable_block_reusableBlock = Object(external_this_wp_element_["createElement"])(external_this_wp_primitives_["SVG"], {
 556    xmlns: "http://www.w3.org/2000/svg",
 557    viewBox: "0 0 24 24"
 558  }, Object(external_this_wp_element_["createElement"])(external_this_wp_primitives_["Path"], {
 559    d: "M7 7.2h8.2L13.5 9l1.1 1.1 3.6-3.6-3.5-4-1.1 1 1.9 2.3H7c-.9 0-1.7.3-2.3.9-1.4 1.5-1.4 4.2-1.4 5.6v.2h1.5v-.3c0-1.1 0-3.5 1-4.5.3-.3.7-.5 1.2-.5zm13.8 4V11h-1.5v.3c0 1.1 0 3.5-1 4.5-.3.3-.7.5-1.3.5H8.8l1.7-1.7-1.1-1.1L5.9 17l3.5 4 1.1-1-1.9-2.3H17c.9 0 1.7-.3 2.3-.9 1.5-1.4 1.5-4.2 1.5-5.6z"
 560  }));
 561  /* harmony default export */ var reusable_block = (reusable_block_reusableBlock);
 562  
 563  // CONCATENATED MODULE: ./node_modules/@wordpress/reusable-blocks/build-module/components/reusable-blocks-menu-items/reusable-block-convert-button.js
 564  
 565  
 566  
 567  
 568  /**
 569   * WordPress dependencies
 570   */
 571  
 572  
 573  
 574  
 575  
 576  
 577  
 578  /**
 579   * Internal dependencies
 580   */
 581  
 582  
 583  /**
 584   * Menu control to convert block(s) to reusable block.
 585   *
 586   * @param {Object}   props              Component props.
 587   * @param {string[]} props.clientIds    Client ids of selected blocks.
 588   * @param {string}   props.rootClientId ID of the currently selected top-level block.
 589   * @return {import('@wordpress/element').WPComponent} The menu control or null.
 590   */
 591  
 592  function ReusableBlockConvertButton(_ref) {
 593    var clientIds = _ref.clientIds,
 594        rootClientId = _ref.rootClientId;
 595    var canConvert = Object(external_this_wp_data_["useSelect"])(function (select) {
 596      var _getBlocksByClientId;
 597  
 598      var _select = select('core'),
 599          canUser = _select.canUser;
 600  
 601      var _select2 = select('core/block-editor'),
 602          getBlocksByClientId = _select2.getBlocksByClientId,
 603          canInsertBlockType = _select2.canInsertBlockType;
 604  
 605      var blocks = (_getBlocksByClientId = getBlocksByClientId(clientIds)) !== null && _getBlocksByClientId !== void 0 ? _getBlocksByClientId : [];
 606      var isReusable = blocks.length === 1 && blocks[0] && Object(external_this_wp_blocks_["isReusableBlock"])(blocks[0]) && !!select('core').getEntityRecord('postType', 'wp_block', blocks[0].attributes.ref);
 607  
 608      var _canConvert = // Hide when this is already a reusable block.
 609      !isReusable && // Hide when reusable blocks are disabled.
 610      canInsertBlockType('core/block', rootClientId) && blocks.every(function (block) {
 611        return (// Guard against the case where a regular block has *just* been converted.
 612          !!block && // Hide on invalid blocks.
 613          block.isValid && // Hide when block doesn't support being made reusable.
 614          Object(external_this_wp_blocks_["hasBlockSupport"])(block.name, 'reusable', true)
 615        );
 616      }) && // Hide when current doesn't have permission to do that.
 617      !!canUser('create', 'blocks');
 618  
 619      return _canConvert;
 620    }, [clientIds]);
 621  
 622    var _useDispatch = Object(external_this_wp_data_["useDispatch"])(STORE_KEY),
 623        convertBlocksToReusable = _useDispatch.__experimentalConvertBlocksToReusable;
 624  
 625    var _useDispatch2 = Object(external_this_wp_data_["useDispatch"])('core/notices'),
 626        createSuccessNotice = _useDispatch2.createSuccessNotice,
 627        createErrorNotice = _useDispatch2.createErrorNotice;
 628  
 629    var onConvert = Object(external_this_wp_element_["useCallback"])( /*#__PURE__*/Object(asyncToGenerator["a" /* default */])( /*#__PURE__*/external_this_regeneratorRuntime_default.a.mark(function _callee() {
 630      return external_this_regeneratorRuntime_default.a.wrap(function _callee$(_context) {
 631        while (1) {
 632          switch (_context.prev = _context.next) {
 633            case 0:
 634              _context.prev = 0;
 635              _context.next = 3;
 636              return convertBlocksToReusable(clientIds);
 637  
 638            case 3:
 639              createSuccessNotice(Object(external_this_wp_i18n_["__"])('Block created.'), {
 640                type: 'snackbar'
 641              });
 642              _context.next = 9;
 643              break;
 644  
 645            case 6:
 646              _context.prev = 6;
 647              _context.t0 = _context["catch"](0);
 648              createErrorNotice(_context.t0.message, {
 649                type: 'snackbar'
 650              });
 651  
 652            case 9:
 653            case "end":
 654              return _context.stop();
 655          }
 656        }
 657      }, _callee, null, [[0, 6]]);
 658    })), [clientIds]);
 659  
 660    if (!canConvert) {
 661      return null;
 662    }
 663  
 664    return Object(external_this_wp_element_["createElement"])(external_this_wp_blockEditor_["BlockSettingsMenuControls"], null, function (_ref3) {
 665      var onClose = _ref3.onClose;
 666      return Object(external_this_wp_element_["createElement"])(external_this_wp_components_["MenuItem"], {
 667        icon: reusable_block,
 668        onClick: function onClick() {
 669          onConvert();
 670          onClose();
 671        }
 672      }, Object(external_this_wp_i18n_["__"])('Add to Reusable blocks'));
 673    });
 674  }
 675  
 676  // CONCATENATED MODULE: ./node_modules/@wordpress/reusable-blocks/build-module/components/reusable-blocks-menu-items/reusable-block-delete-button.js
 677  
 678  
 679  
 680  
 681  /**
 682   * WordPress dependencies
 683   */
 684  
 685  
 686  
 687  
 688  
 689  
 690  /**
 691   * Internal dependencies
 692   */
 693  
 694  
 695  
 696  function ReusableBlockDeleteButton(_ref) {
 697    var clientId = _ref.clientId;
 698  
 699    var _useSelect = Object(external_this_wp_data_["useSelect"])(function (select) {
 700      var _select = select('core/block-editor'),
 701          getBlock = _select.getBlock;
 702  
 703      var _select2 = select('core'),
 704          canUser = _select2.canUser;
 705  
 706      var blockObj = getBlock(clientId);
 707      var reusableBlock = blockObj && Object(external_this_wp_blocks_["isReusableBlock"])(blockObj) ? select('core').getEntityRecord('postType', 'wp_block', blockObj.attributes.ref) : null;
 708      return {
 709        block: blockObj,
 710        isVisible: !!reusableBlock && (reusableBlock.isTemporary || !!canUser('delete', 'blocks', reusableBlock.id)),
 711        isDisabled: reusableBlock && reusableBlock.isTemporary
 712      };
 713    }, [clientId]),
 714        isVisible = _useSelect.isVisible,
 715        isDisabled = _useSelect.isDisabled,
 716        block = _useSelect.block;
 717  
 718    var _useDispatch = Object(external_this_wp_data_["useDispatch"])(STORE_KEY),
 719        deleteReusableBlock = _useDispatch.__experimentalDeleteReusableBlock;
 720  
 721    var _useDispatch2 = Object(external_this_wp_data_["useDispatch"])('core/notices'),
 722        createSuccessNotice = _useDispatch2.createSuccessNotice,
 723        createErrorNotice = _useDispatch2.createErrorNotice;
 724  
 725    var onDelete = Object(external_this_wp_element_["useCallback"])( /*#__PURE__*/Object(asyncToGenerator["a" /* default */])( /*#__PURE__*/external_this_regeneratorRuntime_default.a.mark(function _callee() {
 726      return external_this_regeneratorRuntime_default.a.wrap(function _callee$(_context) {
 727        while (1) {
 728          switch (_context.prev = _context.next) {
 729            case 0:
 730              _context.prev = 0;
 731              _context.next = 3;
 732              return deleteReusableBlock(block.attributes.ref);
 733  
 734            case 3:
 735              createSuccessNotice(Object(external_this_wp_i18n_["__"])('Block deleted.'), {
 736                type: 'snackbar'
 737              });
 738              _context.next = 9;
 739              break;
 740  
 741            case 6:
 742              _context.prev = 6;
 743              _context.t0 = _context["catch"](0);
 744              createErrorNotice(_context.t0.message, {
 745                type: 'snackbar'
 746              });
 747  
 748            case 9:
 749            case "end":
 750              return _context.stop();
 751          }
 752        }
 753      }, _callee, null, [[0, 6]]);
 754    })), [block]);
 755  
 756    if (!isVisible) {
 757      return null;
 758    }
 759  
 760    return Object(external_this_wp_element_["createElement"])(external_this_wp_blockEditor_["BlockSettingsMenuControls"], null, function (_ref3) {
 761      var onClose = _ref3.onClose;
 762      return Object(external_this_wp_element_["createElement"])(external_this_wp_components_["MenuItem"], {
 763        disabled: isDisabled,
 764        onClick: function onClick() {
 765          // eslint-disable-next-line no-alert
 766          var hasConfirmed = window.confirm( // eslint-disable-next-line @wordpress/i18n-no-collapsible-whitespace
 767          Object(external_this_wp_i18n_["__"])('Are you sure you want to delete this Reusable Block?\n\n' + 'It will be permanently removed from all posts and pages that use it.'));
 768  
 769          if (hasConfirmed) {
 770            onDelete();
 771            onClose();
 772          }
 773        }
 774      }, Object(external_this_wp_i18n_["__"])('Remove from Reusable blocks'));
 775    });
 776  }
 777  
 778  /* harmony default export */ var reusable_block_delete_button = (ReusableBlockDeleteButton);
 779  
 780  // CONCATENATED MODULE: ./node_modules/@wordpress/reusable-blocks/build-module/components/reusable-blocks-menu-items/index.js
 781  
 782  
 783  /**
 784   * WordPress dependencies
 785   */
 786  
 787  /**
 788   * Internal dependencies
 789   */
 790  
 791  
 792  
 793  
 794  function ReusableBlocksMenuItems(_ref) {
 795    var clientIds = _ref.clientIds,
 796        rootClientId = _ref.rootClientId;
 797    return Object(external_this_wp_element_["createElement"])(external_this_wp_element_["Fragment"], null, Object(external_this_wp_element_["createElement"])(ReusableBlockConvertButton, {
 798      clientIds: clientIds,
 799      rootClientId: rootClientId
 800    }), clientIds.length === 1 && Object(external_this_wp_element_["createElement"])(reusable_block_delete_button, {
 801      clientId: clientIds[0]
 802    }));
 803  }
 804  
 805  /* harmony default export */ var reusable_blocks_menu_items = (Object(external_this_wp_data_["withSelect"])(function (select) {
 806    var _select = select('core/block-editor'),
 807        getSelectedBlockClientIds = _select.getSelectedBlockClientIds;
 808  
 809    return {
 810      clientIds: getSelectedBlockClientIds()
 811    };
 812  })(ReusableBlocksMenuItems));
 813  
 814  // CONCATENATED MODULE: ./node_modules/@wordpress/reusable-blocks/build-module/components/index.js
 815  
 816  
 817  // CONCATENATED MODULE: ./node_modules/@wordpress/reusable-blocks/build-module/index.js
 818  /**
 819   * WordPress dependencies
 820   */
 821  
 822  
 823  
 824  /**
 825   * Internal dependencies
 826   */
 827  
 828  
 829  
 830  
 831  
 832  /***/ }),
 833  
 834  /***/ 5:
 835  /***/ (function(module, __webpack_exports__, __webpack_require__) {
 836  
 837  "use strict";
 838  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _defineProperty; });
 839  function _defineProperty(obj, key, value) {
 840    if (key in obj) {
 841      Object.defineProperty(obj, key, {
 842        value: value,
 843        enumerable: true,
 844        configurable: true,
 845        writable: true
 846      });
 847    } else {
 848      obj[key] = value;
 849    }
 850  
 851    return obj;
 852  }
 853  
 854  /***/ }),
 855  
 856  /***/ 6:
 857  /***/ (function(module, exports) {
 858  
 859  (function() { module.exports = this["wp"]["blockEditor"]; }());
 860  
 861  /***/ }),
 862  
 863  /***/ 7:
 864  /***/ (function(module, exports) {
 865  
 866  (function() { module.exports = this["wp"]["primitives"]; }());
 867  
 868  /***/ }),
 869  
 870  /***/ 83:
 871  /***/ (function(module, exports) {
 872  
 873  (function() { module.exports = this["wp"]["coreData"]; }());
 874  
 875  /***/ }),
 876  
 877  /***/ 92:
 878  /***/ (function(module, exports) {
 879  
 880  (function() { module.exports = this["wp"]["notices"]; }());
 881  
 882  /***/ })
 883  
 884  /******/ });


Generated : Mon Jan 18 08:20:02 2021 Cross-referenced by PHPXref