You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

507 lines
20 KiB

1 year ago
  1. /******/ (function() { // webpackBootstrap
  2. /******/ "use strict";
  3. /******/ // The require scope
  4. /******/ var __webpack_require__ = {};
  5. /******/
  6. /************************************************************************/
  7. /******/ /* webpack/runtime/define property getters */
  8. /******/ !function() {
  9. /******/ // define getter functions for harmony exports
  10. /******/ __webpack_require__.d = function(exports, definition) {
  11. /******/ for(var key in definition) {
  12. /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  13. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  14. /******/ }
  15. /******/ }
  16. /******/ };
  17. /******/ }();
  18. /******/
  19. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  20. /******/ !function() {
  21. /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
  22. /******/ }();
  23. /******/
  24. /******/ /* webpack/runtime/make namespace object */
  25. /******/ !function() {
  26. /******/ // define __esModule on exports
  27. /******/ __webpack_require__.r = function(exports) {
  28. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  29. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  30. /******/ }
  31. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  32. /******/ };
  33. /******/ }();
  34. /******/
  35. /************************************************************************/
  36. var __webpack_exports__ = {};
  37. // ESM COMPAT FLAG
  38. __webpack_require__.r(__webpack_exports__);
  39. // EXPORTS
  40. __webpack_require__.d(__webpack_exports__, {
  41. ReusableBlocksMenuItems: function() { return /* reexport */ ReusableBlocksMenuItems; },
  42. store: function() { return /* reexport */ store; }
  43. });
  44. // NAMESPACE OBJECT: ./node_modules/@wordpress/reusable-blocks/build-module/store/actions.js
  45. var actions_namespaceObject = {};
  46. __webpack_require__.r(actions_namespaceObject);
  47. __webpack_require__.d(actions_namespaceObject, {
  48. __experimentalConvertBlockToStatic: function() { return __experimentalConvertBlockToStatic; },
  49. __experimentalConvertBlocksToReusable: function() { return __experimentalConvertBlocksToReusable; },
  50. __experimentalDeleteReusableBlock: function() { return __experimentalDeleteReusableBlock; },
  51. __experimentalSetEditingReusableBlock: function() { return __experimentalSetEditingReusableBlock; }
  52. });
  53. // NAMESPACE OBJECT: ./node_modules/@wordpress/reusable-blocks/build-module/store/selectors.js
  54. var selectors_namespaceObject = {};
  55. __webpack_require__.r(selectors_namespaceObject);
  56. __webpack_require__.d(selectors_namespaceObject, {
  57. __experimentalIsEditingReusableBlock: function() { return __experimentalIsEditingReusableBlock; }
  58. });
  59. ;// CONCATENATED MODULE: external ["wp","data"]
  60. var external_wp_data_namespaceObject = window["wp"]["data"];
  61. ;// CONCATENATED MODULE: external ["wp","blockEditor"]
  62. var external_wp_blockEditor_namespaceObject = window["wp"]["blockEditor"];
  63. ;// CONCATENATED MODULE: external ["wp","blocks"]
  64. var external_wp_blocks_namespaceObject = window["wp"]["blocks"];
  65. ;// CONCATENATED MODULE: external ["wp","i18n"]
  66. var external_wp_i18n_namespaceObject = window["wp"]["i18n"];
  67. ;// CONCATENATED MODULE: ./node_modules/@wordpress/reusable-blocks/build-module/store/actions.js
  68. /**
  69. * WordPress dependencies
  70. */
  71. /**
  72. * Returns a generator converting a reusable block into a static block.
  73. *
  74. * @param {string} clientId The client ID of the block to attach.
  75. */
  76. const __experimentalConvertBlockToStatic = clientId => ({
  77. registry
  78. }) => {
  79. const oldBlock = registry.select(external_wp_blockEditor_namespaceObject.store).getBlock(clientId);
  80. const reusableBlock = registry.select('core').getEditedEntityRecord('postType', 'wp_block', oldBlock.attributes.ref);
  81. const newBlocks = (0,external_wp_blocks_namespaceObject.parse)(typeof reusableBlock.content === 'function' ? reusableBlock.content(reusableBlock) : reusableBlock.content);
  82. registry.dispatch(external_wp_blockEditor_namespaceObject.store).replaceBlocks(oldBlock.clientId, newBlocks);
  83. };
  84. /**
  85. * Returns a generator converting one or more static blocks into a pattern.
  86. *
  87. * @param {string[]} clientIds The client IDs of the block to detach.
  88. * @param {string} title Pattern title.
  89. * @param {undefined|'unsynced'} syncType They way block is synced, current undefined (synced) and 'unsynced'.
  90. */
  91. const __experimentalConvertBlocksToReusable = (clientIds, title, syncType) => async ({
  92. registry,
  93. dispatch
  94. }) => {
  95. const meta = syncType === 'unsynced' ? {
  96. wp_pattern_sync_status: syncType
  97. } : undefined;
  98. const reusableBlock = {
  99. title: title || (0,external_wp_i18n_namespaceObject.__)('Untitled pattern block'),
  100. content: (0,external_wp_blocks_namespaceObject.serialize)(registry.select(external_wp_blockEditor_namespaceObject.store).getBlocksByClientId(clientIds)),
  101. status: 'publish',
  102. meta
  103. };
  104. const updatedRecord = await registry.dispatch('core').saveEntityRecord('postType', 'wp_block', reusableBlock);
  105. if (syncType === 'unsynced') {
  106. return;
  107. }
  108. const newBlock = (0,external_wp_blocks_namespaceObject.createBlock)('core/block', {
  109. ref: updatedRecord.id
  110. });
  111. registry.dispatch(external_wp_blockEditor_namespaceObject.store).replaceBlocks(clientIds, newBlock);
  112. dispatch.__experimentalSetEditingReusableBlock(newBlock.clientId, true);
  113. };
  114. /**
  115. * Returns a generator deleting a reusable block.
  116. *
  117. * @param {string} id The ID of the reusable block to delete.
  118. */
  119. const __experimentalDeleteReusableBlock = id => async ({
  120. registry
  121. }) => {
  122. const reusableBlock = registry.select('core').getEditedEntityRecord('postType', 'wp_block', id);
  123. // Don't allow a reusable block with a temporary ID to be deleted.
  124. if (!reusableBlock) {
  125. return;
  126. }
  127. // Remove any other blocks that reference this reusable block.
  128. const allBlocks = registry.select(external_wp_blockEditor_namespaceObject.store).getBlocks();
  129. const associatedBlocks = allBlocks.filter(block => (0,external_wp_blocks_namespaceObject.isReusableBlock)(block) && block.attributes.ref === id);
  130. const associatedBlockClientIds = associatedBlocks.map(block => block.clientId);
  131. // Remove the parsed block.
  132. if (associatedBlockClientIds.length) {
  133. registry.dispatch(external_wp_blockEditor_namespaceObject.store).removeBlocks(associatedBlockClientIds);
  134. }
  135. await registry.dispatch('core').deleteEntityRecord('postType', 'wp_block', id);
  136. };
  137. /**
  138. * Returns an action descriptor for SET_EDITING_REUSABLE_BLOCK action.
  139. *
  140. * @param {string} clientId The clientID of the reusable block to target.
  141. * @param {boolean} isEditing Whether the block should be in editing state.
  142. * @return {Object} Action descriptor.
  143. */
  144. function __experimentalSetEditingReusableBlock(clientId, isEditing) {
  145. return {
  146. type: 'SET_EDITING_REUSABLE_BLOCK',
  147. clientId,
  148. isEditing
  149. };
  150. }
  151. ;// CONCATENATED MODULE: ./node_modules/@wordpress/reusable-blocks/build-module/store/reducer.js
  152. /**
  153. * WordPress dependencies
  154. */
  155. function isEditingReusableBlock(state = {}, action) {
  156. if (action?.type === 'SET_EDITING_REUSABLE_BLOCK') {
  157. return {
  158. ...state,
  159. [action.clientId]: action.isEditing
  160. };
  161. }
  162. return state;
  163. }
  164. /* harmony default export */ var reducer = ((0,external_wp_data_namespaceObject.combineReducers)({
  165. isEditingReusableBlock
  166. }));
  167. ;// CONCATENATED MODULE: ./node_modules/@wordpress/reusable-blocks/build-module/store/selectors.js
  168. /**
  169. * Returns true if reusable block is in the editing state.
  170. *
  171. * @param {Object} state Global application state.
  172. * @param {number} clientId the clientID of the block.
  173. * @return {boolean} Whether the reusable block is in the editing state.
  174. */
  175. function __experimentalIsEditingReusableBlock(state, clientId) {
  176. return state.isEditingReusableBlock[clientId];
  177. }
  178. ;// CONCATENATED MODULE: ./node_modules/@wordpress/reusable-blocks/build-module/store/index.js
  179. /**
  180. * WordPress dependencies
  181. */
  182. /**
  183. * Internal dependencies
  184. */
  185. const STORE_NAME = 'core/reusable-blocks';
  186. /**
  187. * Store definition for the reusable blocks namespace.
  188. *
  189. * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
  190. *
  191. * @type {Object}
  192. */
  193. const store = (0,external_wp_data_namespaceObject.createReduxStore)(STORE_NAME, {
  194. actions: actions_namespaceObject,
  195. reducer: reducer,
  196. selectors: selectors_namespaceObject
  197. });
  198. (0,external_wp_data_namespaceObject.register)(store);
  199. ;// CONCATENATED MODULE: external ["wp","element"]
  200. var external_wp_element_namespaceObject = window["wp"]["element"];
  201. ;// CONCATENATED MODULE: external ["wp","components"]
  202. var external_wp_components_namespaceObject = window["wp"]["components"];
  203. ;// CONCATENATED MODULE: external ["wp","primitives"]
  204. var external_wp_primitives_namespaceObject = window["wp"]["primitives"];
  205. ;// CONCATENATED MODULE: ./node_modules/@wordpress/icons/build-module/library/symbol.js
  206. /**
  207. * WordPress dependencies
  208. */
  209. const symbol = (0,external_wp_element_namespaceObject.createElement)(external_wp_primitives_namespaceObject.SVG, {
  210. xmlns: "http://www.w3.org/2000/svg",
  211. viewBox: "0 0 24 24"
  212. }, (0,external_wp_element_namespaceObject.createElement)(external_wp_primitives_namespaceObject.Path, {
  213. d: "M21.3 10.8l-5.6-5.6c-.7-.7-1.8-.7-2.5 0l-5.6 5.6c-.7.7-.7 1.8 0 2.5l5.6 5.6c.3.3.8.5 1.2.5s.9-.2 1.2-.5l5.6-5.6c.8-.7.8-1.9.1-2.5zm-1 1.4l-5.6 5.6c-.1.1-.3.1-.4 0l-5.6-5.6c-.1-.1-.1-.3 0-.4l5.6-5.6s.1-.1.2-.1.1 0 .2.1l5.6 5.6c.1.1.1.3 0 .4zm-16.6-.4L10 5.5l-1-1-6.3 6.3c-.7.7-.7 1.8 0 2.5L9 19.5l1.1-1.1-6.3-6.3c-.2 0-.2-.2-.1-.3z"
  214. }));
  215. /* harmony default export */ var library_symbol = (symbol);
  216. ;// CONCATENATED MODULE: external ["wp","notices"]
  217. var external_wp_notices_namespaceObject = window["wp"]["notices"];
  218. ;// CONCATENATED MODULE: external ["wp","coreData"]
  219. var external_wp_coreData_namespaceObject = window["wp"]["coreData"];
  220. ;// CONCATENATED MODULE: external ["wp","privateApis"]
  221. var external_wp_privateApis_namespaceObject = window["wp"]["privateApis"];
  222. ;// CONCATENATED MODULE: ./node_modules/@wordpress/reusable-blocks/build-module/lock-unlock.js
  223. /**
  224. * WordPress dependencies
  225. */
  226. const {
  227. unlock
  228. } = (0,external_wp_privateApis_namespaceObject.__dangerousOptInToUnstableAPIsOnlyForCoreModules)('I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.', '@wordpress/reusable-blocks');
  229. ;// CONCATENATED MODULE: ./node_modules/@wordpress/reusable-blocks/build-module/components/reusable-blocks-menu-items/reusable-block-convert-button.js
  230. /**
  231. * WordPress dependencies
  232. */
  233. /**
  234. * Internal dependencies
  235. */
  236. /**
  237. * Menu control to convert block(s) to reusable block.
  238. *
  239. * @param {Object} props Component props.
  240. * @param {string[]} props.clientIds Client ids of selected blocks.
  241. * @param {string} props.rootClientId ID of the currently selected top-level block.
  242. * @param {()=>void} props.onClose Callback to close the menu.
  243. * @return {import('@wordpress/element').WPComponent} The menu control or null.
  244. */
  245. function ReusableBlockConvertButton({
  246. clientIds,
  247. rootClientId,
  248. onClose
  249. }) {
  250. const {
  251. useReusableBlocksRenameHint,
  252. ReusableBlocksRenameHint
  253. } = unlock(external_wp_blockEditor_namespaceObject.privateApis);
  254. const showRenameHint = useReusableBlocksRenameHint();
  255. const [syncType, setSyncType] = (0,external_wp_element_namespaceObject.useState)(undefined);
  256. const [isModalOpen, setIsModalOpen] = (0,external_wp_element_namespaceObject.useState)(false);
  257. const [title, setTitle] = (0,external_wp_element_namespaceObject.useState)('');
  258. const canConvert = (0,external_wp_data_namespaceObject.useSelect)(select => {
  259. var _getBlocksByClientId;
  260. const {
  261. canUser
  262. } = select(external_wp_coreData_namespaceObject.store);
  263. const {
  264. getBlocksByClientId,
  265. canInsertBlockType,
  266. getBlockRootClientId
  267. } = select(external_wp_blockEditor_namespaceObject.store);
  268. const rootId = rootClientId || (clientIds.length > 0 ? getBlockRootClientId(clientIds[0]) : undefined);
  269. const blocks = (_getBlocksByClientId = getBlocksByClientId(clientIds)) !== null && _getBlocksByClientId !== void 0 ? _getBlocksByClientId : [];
  270. const isReusable = blocks.length === 1 && blocks[0] && (0,external_wp_blocks_namespaceObject.isReusableBlock)(blocks[0]) && !!select(external_wp_coreData_namespaceObject.store).getEntityRecord('postType', 'wp_block', blocks[0].attributes.ref);
  271. const _canConvert =
  272. // Hide when this is already a reusable block.
  273. !isReusable &&
  274. // Hide when reusable blocks are disabled.
  275. canInsertBlockType('core/block', rootId) && blocks.every(block =>
  276. // Guard against the case where a regular block has *just* been converted.
  277. !!block &&
  278. // Hide on invalid blocks.
  279. block.isValid &&
  280. // Hide when block doesn't support being made reusable.
  281. (0,external_wp_blocks_namespaceObject.hasBlockSupport)(block.name, 'reusable', true)) &&
  282. // Hide when current doesn't have permission to do that.
  283. !!canUser('create', 'blocks');
  284. return _canConvert;
  285. }, [clientIds, rootClientId]);
  286. const {
  287. __experimentalConvertBlocksToReusable: convertBlocksToReusable
  288. } = (0,external_wp_data_namespaceObject.useDispatch)(store);
  289. const {
  290. createSuccessNotice,
  291. createErrorNotice
  292. } = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_notices_namespaceObject.store);
  293. const onConvert = (0,external_wp_element_namespaceObject.useCallback)(async function (reusableBlockTitle) {
  294. try {
  295. await convertBlocksToReusable(clientIds, reusableBlockTitle, syncType);
  296. createSuccessNotice(!syncType ? (0,external_wp_i18n_namespaceObject.sprintf)(
  297. // translators: %s: the name the user has given to the pattern.
  298. (0,external_wp_i18n_namespaceObject.__)('Synced pattern created: %s'), reusableBlockTitle) : (0,external_wp_i18n_namespaceObject.sprintf)(
  299. // translators: %s: the name the user has given to the pattern.
  300. (0,external_wp_i18n_namespaceObject.__)('Unsynced pattern created: %s'), reusableBlockTitle), {
  301. type: 'snackbar',
  302. id: 'convert-to-reusable-block-success'
  303. });
  304. } catch (error) {
  305. createErrorNotice(error.message, {
  306. type: 'snackbar',
  307. id: 'convert-to-reusable-block-error'
  308. });
  309. }
  310. }, [convertBlocksToReusable, clientIds, syncType, createSuccessNotice, createErrorNotice]);
  311. if (!canConvert) {
  312. return null;
  313. }
  314. return (0,external_wp_element_namespaceObject.createElement)(external_wp_element_namespaceObject.Fragment, null, (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.MenuItem, {
  315. icon: library_symbol,
  316. onClick: () => setIsModalOpen(true)
  317. }, showRenameHint ? (0,external_wp_i18n_namespaceObject.__)('Create pattern/reusable block') : (0,external_wp_i18n_namespaceObject.__)('Create pattern')), isModalOpen && (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Modal, {
  318. title: (0,external_wp_i18n_namespaceObject.__)('Create pattern'),
  319. onRequestClose: () => {
  320. setIsModalOpen(false);
  321. setTitle('');
  322. },
  323. overlayClassName: "reusable-blocks-menu-items__convert-modal"
  324. }, (0,external_wp_element_namespaceObject.createElement)("form", {
  325. onSubmit: event => {
  326. event.preventDefault();
  327. onConvert(title);
  328. setIsModalOpen(false);
  329. setTitle('');
  330. onClose();
  331. }
  332. }, (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.__experimentalVStack, {
  333. spacing: "5"
  334. }, (0,external_wp_element_namespaceObject.createElement)(ReusableBlocksRenameHint, null), (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.TextControl, {
  335. __nextHasNoMarginBottom: true,
  336. label: (0,external_wp_i18n_namespaceObject.__)('Name'),
  337. value: title,
  338. onChange: setTitle,
  339. placeholder: (0,external_wp_i18n_namespaceObject.__)('My pattern')
  340. }), (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.ToggleControl, {
  341. label: (0,external_wp_i18n_namespaceObject.__)('Synced'),
  342. help: (0,external_wp_i18n_namespaceObject.__)('Editing the pattern will update it anywhere it is used.'),
  343. checked: !syncType,
  344. onChange: () => {
  345. setSyncType(!syncType ? 'unsynced' : undefined);
  346. }
  347. }), (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.__experimentalHStack, {
  348. justify: "right"
  349. }, (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Button, {
  350. variant: "tertiary",
  351. onClick: () => {
  352. setIsModalOpen(false);
  353. setTitle('');
  354. }
  355. }, (0,external_wp_i18n_namespaceObject.__)('Cancel')), (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Button, {
  356. variant: "primary",
  357. type: "submit"
  358. }, (0,external_wp_i18n_namespaceObject.__)('Create')))))));
  359. }
  360. ;// CONCATENATED MODULE: external ["wp","url"]
  361. var external_wp_url_namespaceObject = window["wp"]["url"];
  362. ;// CONCATENATED MODULE: ./node_modules/@wordpress/reusable-blocks/build-module/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js
  363. /**
  364. * WordPress dependencies
  365. */
  366. /**
  367. * Internal dependencies
  368. */
  369. function ReusableBlocksManageButton({
  370. clientId
  371. }) {
  372. const {
  373. canRemove,
  374. isVisible,
  375. innerBlockCount,
  376. managePatternsUrl
  377. } = (0,external_wp_data_namespaceObject.useSelect)(select => {
  378. const {
  379. getBlock,
  380. canRemoveBlock,
  381. getBlockCount,
  382. getSettings
  383. } = select(external_wp_blockEditor_namespaceObject.store);
  384. const {
  385. canUser
  386. } = select(external_wp_coreData_namespaceObject.store);
  387. const reusableBlock = getBlock(clientId);
  388. const isBlockTheme = getSettings().__unstableIsBlockBasedTheme;
  389. return {
  390. canRemove: canRemoveBlock(clientId),
  391. isVisible: !!reusableBlock && (0,external_wp_blocks_namespaceObject.isReusableBlock)(reusableBlock) && !!canUser('update', 'blocks', reusableBlock.attributes.ref),
  392. innerBlockCount: getBlockCount(clientId),
  393. // The site editor and templates both check whether the user
  394. // has edit_theme_options capabilities. We can leverage that here
  395. // and omit the manage patterns link if the user can't access it.
  396. managePatternsUrl: isBlockTheme && canUser('read', 'templates') ? (0,external_wp_url_namespaceObject.addQueryArgs)('site-editor.php', {
  397. path: '/patterns'
  398. }) : (0,external_wp_url_namespaceObject.addQueryArgs)('edit.php', {
  399. post_type: 'wp_block'
  400. })
  401. };
  402. }, [clientId]);
  403. const {
  404. __experimentalConvertBlockToStatic: convertBlockToStatic
  405. } = (0,external_wp_data_namespaceObject.useDispatch)(store);
  406. if (!isVisible) {
  407. return null;
  408. }
  409. return (0,external_wp_element_namespaceObject.createElement)(external_wp_element_namespaceObject.Fragment, null, (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.MenuItem, {
  410. href: managePatternsUrl
  411. }, (0,external_wp_i18n_namespaceObject.__)('Manage patterns')), canRemove && (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.MenuItem, {
  412. onClick: () => convertBlockToStatic(clientId)
  413. }, innerBlockCount > 1 ? (0,external_wp_i18n_namespaceObject.__)('Detach patterns') : (0,external_wp_i18n_namespaceObject.__)('Detach pattern')));
  414. }
  415. /* harmony default export */ var reusable_blocks_manage_button = (ReusableBlocksManageButton);
  416. ;// CONCATENATED MODULE: ./node_modules/@wordpress/reusable-blocks/build-module/components/reusable-blocks-menu-items/index.js
  417. /**
  418. * WordPress dependencies
  419. */
  420. /**
  421. * Internal dependencies
  422. */
  423. function ReusableBlocksMenuItems({
  424. rootClientId
  425. }) {
  426. return (0,external_wp_element_namespaceObject.createElement)(external_wp_blockEditor_namespaceObject.BlockSettingsMenuControls, null, ({
  427. onClose,
  428. selectedClientIds
  429. }) => (0,external_wp_element_namespaceObject.createElement)(external_wp_element_namespaceObject.Fragment, null, (0,external_wp_element_namespaceObject.createElement)(ReusableBlockConvertButton, {
  430. clientIds: selectedClientIds,
  431. rootClientId: rootClientId,
  432. onClose: onClose
  433. }), selectedClientIds.length === 1 && (0,external_wp_element_namespaceObject.createElement)(reusable_blocks_manage_button, {
  434. clientId: selectedClientIds[0]
  435. })));
  436. }
  437. ;// CONCATENATED MODULE: ./node_modules/@wordpress/reusable-blocks/build-module/components/index.js
  438. ;// CONCATENATED MODULE: ./node_modules/@wordpress/reusable-blocks/build-module/index.js
  439. (window.wp = window.wp || {}).reusableBlocks = __webpack_exports__;
  440. /******/ })()
  441. ;