| 1 |
/******/ (() => { // webpackBootstrap |
| 2 |
/******/ "use strict"; |
| 3 |
/******/ // The require scope |
| 4 |
/******/ var __webpack_require__ = {}; |
| 5 |
/******/ |
| 6 |
/************************************************************************/ |
| 7 |
/******/ /* webpack/runtime/define property getters */ |
| 8 |
/******/ (() => { |
| 9 |
/******/ // define getter functions for harmony exports |
| 10 |
/******/ __webpack_require__.d = (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 |
/******/ (() => { |
| 21 |
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) |
| 22 |
/******/ })(); |
| 23 |
/******/ |
| 24 |
/******/ /* webpack/runtime/make namespace object */ |
| 25 |
/******/ (() => { |
| 26 |
/******/ // define __esModule on exports |
| 27 |
/******/ __webpack_require__.r = (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 |
|
| 40 |
// EXPORTS |
| 41 |
__webpack_require__.d(__webpack_exports__, { |
| 42 |
"privateApis": () => (/* reexport */ privateApis) |
| 43 |
}); |
| 44 |
|
| 45 |
// NAMESPACE OBJECT: ./packages/patterns/build-module/store/actions.js |
| 46 |
var actions_namespaceObject = {}; |
| 47 |
__webpack_require__.r(actions_namespaceObject); |
| 48 |
__webpack_require__.d(actions_namespaceObject, { |
| 49 |
"__experimentalConvertSyncedPatternToStatic": () => (__experimentalConvertSyncedPatternToStatic), |
| 50 |
"__experimentalCreatePattern": () => (__experimentalCreatePattern), |
| 51 |
"__experimentalSetEditingPattern": () => (__experimentalSetEditingPattern) |
| 52 |
}); |
| 53 |
|
| 54 |
// NAMESPACE OBJECT: ./packages/patterns/build-module/store/selectors.js |
| 55 |
var selectors_namespaceObject = {}; |
| 56 |
__webpack_require__.r(selectors_namespaceObject); |
| 57 |
__webpack_require__.d(selectors_namespaceObject, { |
| 58 |
"__experimentalIsEditingPattern": () => (__experimentalIsEditingPattern) |
| 59 |
}); |
| 60 |
|
| 61 |
;// CONCATENATED MODULE: external ["wp","data"] |
| 62 |
const external_wp_data_namespaceObject = window["wp"]["data"]; |
| 63 |
;// CONCATENATED MODULE: ./packages/patterns/build-module/store/reducer.js |
| 64 |
/** |
| 65 |
* WordPress dependencies |
| 66 |
*/ |
| 67 |
|
| 68 |
function isEditingPattern(state = {}, action) { |
| 69 |
if (action?.type === 'SET_EDITING_PATTERN') { |
| 70 |
return { |
| 71 |
...state, |
| 72 |
[action.clientId]: action.isEditing |
| 73 |
}; |
| 74 |
} |
| 75 |
return state; |
| 76 |
} |
| 77 |
/* harmony default export */ const reducer = ((0,external_wp_data_namespaceObject.combineReducers)({ |
| 78 |
isEditingPattern |
| 79 |
})); |
| 80 |
|
| 81 |
;// CONCATENATED MODULE: external ["wp","blocks"] |
| 82 |
const external_wp_blocks_namespaceObject = window["wp"]["blocks"]; |
| 83 |
;// CONCATENATED MODULE: external ["wp","coreData"] |
| 84 |
const external_wp_coreData_namespaceObject = window["wp"]["coreData"]; |
| 85 |
;// CONCATENATED MODULE: external ["wp","blockEditor"] |
| 86 |
const external_wp_blockEditor_namespaceObject = window["wp"]["blockEditor"]; |
| 87 |
;// CONCATENATED MODULE: ./packages/patterns/build-module/store/actions.js |
| 88 |
/** |
| 89 |
* WordPress dependencies |
| 90 |
*/ |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
/** |
| 97 |
* Returns a generator converting one or more static blocks into a pattern, or creating a new empty pattern. |
| 98 |
* |
| 99 |
* @param {string} title Pattern title. |
| 100 |
* @param {'full'|'unsynced'} syncType They way block is synced, 'full' or 'unsynced'. |
| 101 |
* @param {string[]|undefined} clientIds Optional client IDs of blocks to convert to pattern. |
| 102 |
*/ |
| 103 |
const __experimentalCreatePattern = (title, syncType, clientIds) => async ({ |
| 104 |
registry, |
| 105 |
dispatch |
| 106 |
}) => { |
| 107 |
const meta = syncType === 'unsynced' ? { |
| 108 |
wp_pattern_sync_status: syncType |
| 109 |
} : undefined; |
| 110 |
const reusableBlock = { |
| 111 |
title, |
| 112 |
content: clientIds ? (0,external_wp_blocks_namespaceObject.serialize)(registry.select(external_wp_blockEditor_namespaceObject.store).getBlocksByClientId(clientIds)) : undefined, |
| 113 |
status: 'publish', |
| 114 |
meta |
| 115 |
}; |
| 116 |
const updatedRecord = await registry.dispatch(external_wp_coreData_namespaceObject.store).saveEntityRecord('postType', 'wp_block', reusableBlock); |
| 117 |
if (syncType === 'unsynced' || !clientIds) { |
| 118 |
return updatedRecord; |
| 119 |
} |
| 120 |
const newBlock = (0,external_wp_blocks_namespaceObject.createBlock)('core/block', { |
| 121 |
ref: updatedRecord.id |
| 122 |
}); |
| 123 |
registry.dispatch(external_wp_blockEditor_namespaceObject.store).replaceBlocks(clientIds, newBlock); |
| 124 |
dispatch.__experimentalSetEditingPattern(newBlock.clientId, true); |
| 125 |
return updatedRecord; |
| 126 |
}; |
| 127 |
|
| 128 |
/** |
| 129 |
* Returns a generator converting a synced pattern block into a static block. |
| 130 |
* |
| 131 |
* @param {string} clientId The client ID of the block to attach. |
| 132 |
*/ |
| 133 |
const __experimentalConvertSyncedPatternToStatic = clientId => ({ |
| 134 |
registry |
| 135 |
}) => { |
| 136 |
const oldBlock = registry.select(external_wp_blockEditor_namespaceObject.store).getBlock(clientId); |
| 137 |
const pattern = registry.select('core').getEditedEntityRecord('postType', 'wp_block', oldBlock.attributes.ref); |
| 138 |
const newBlocks = (0,external_wp_blocks_namespaceObject.parse)(typeof pattern.content === 'function' ? pattern.content(pattern) : pattern.content); |
| 139 |
registry.dispatch(external_wp_blockEditor_namespaceObject.store).replaceBlocks(oldBlock.clientId, newBlocks); |
| 140 |
}; |
| 141 |
|
| 142 |
/** |
| 143 |
* Returns an action descriptor for SET_EDITING_PATTERN action. |
| 144 |
* |
| 145 |
* @param {string} clientId The clientID of the pattern to target. |
| 146 |
* @param {boolean} isEditing Whether the block should be in editing state. |
| 147 |
* @return {Object} Action descriptor. |
| 148 |
*/ |
| 149 |
function __experimentalSetEditingPattern(clientId, isEditing) { |
| 150 |
return { |
| 151 |
type: 'SET_EDITING_PATTERN', |
| 152 |
clientId, |
| 153 |
isEditing |
| 154 |
}; |
| 155 |
} |
| 156 |
|
| 157 |
;// CONCATENATED MODULE: ./packages/patterns/build-module/store/constants.js |
| 158 |
/** |
| 159 |
* Module Constants |
| 160 |
*/ |
| 161 |
const STORE_NAME = 'core/patterns'; |
| 162 |
|
| 163 |
;// CONCATENATED MODULE: ./packages/patterns/build-module/store/selectors.js |
| 164 |
/** |
| 165 |
* Returns true if pattern is in the editing state. |
| 166 |
* |
| 167 |
* @param {Object} state Global application state. |
| 168 |
* @param {number} clientId the clientID of the block. |
| 169 |
* @return {boolean} Whether the pattern is in the editing state. |
| 170 |
*/ |
| 171 |
function __experimentalIsEditingPattern(state, clientId) { |
| 172 |
return state.isEditingPattern[clientId]; |
| 173 |
} |
| 174 |
|
| 175 |
;// CONCATENATED MODULE: ./packages/patterns/build-module/store/index.js |
| 176 |
/** |
| 177 |
* WordPress dependencies |
| 178 |
*/ |
| 179 |
|
| 180 |
|
| 181 |
/** |
| 182 |
* Internal dependencies |
| 183 |
*/ |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
/** |
| 190 |
* Post editor data store configuration. |
| 191 |
* |
| 192 |
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#registerStore |
| 193 |
* |
| 194 |
* @type {Object} |
| 195 |
*/ |
| 196 |
const storeConfig = { |
| 197 |
reducer: reducer, |
| 198 |
selectors: selectors_namespaceObject, |
| 199 |
actions: actions_namespaceObject |
| 200 |
}; |
| 201 |
|
| 202 |
/** |
| 203 |
* Store definition for the editor namespace. |
| 204 |
* |
| 205 |
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore |
| 206 |
* |
| 207 |
* @type {Object} |
| 208 |
*/ |
| 209 |
const store = (0,external_wp_data_namespaceObject.createReduxStore)(STORE_NAME, { |
| 210 |
...storeConfig |
| 211 |
}); |
| 212 |
(0,external_wp_data_namespaceObject.register)(store); |
| 213 |
|
| 214 |
;// CONCATENATED MODULE: external ["wp","privateApis"] |
| 215 |
const external_wp_privateApis_namespaceObject = window["wp"]["privateApis"]; |
| 216 |
;// CONCATENATED MODULE: ./packages/patterns/build-module/lock-unlock.js |
| 217 |
/** |
| 218 |
* WordPress dependencies |
| 219 |
*/ |
| 220 |
|
| 221 |
const { |
| 222 |
lock, |
| 223 |
unlock |
| 224 |
} = (0,external_wp_privateApis_namespaceObject.__dangerousOptInToUnstableAPIsOnlyForCoreModules)('I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.', '@wordpress/patterns'); |
| 225 |
|
| 226 |
;// CONCATENATED MODULE: external ["wp","element"] |
| 227 |
const external_wp_element_namespaceObject = window["wp"]["element"]; |
| 228 |
;// CONCATENATED MODULE: external ["wp","components"] |
| 229 |
const external_wp_components_namespaceObject = window["wp"]["components"]; |
| 230 |
;// CONCATENATED MODULE: external ["wp","i18n"] |
| 231 |
const external_wp_i18n_namespaceObject = window["wp"]["i18n"]; |
| 232 |
;// CONCATENATED MODULE: external ["wp","notices"] |
| 233 |
const external_wp_notices_namespaceObject = window["wp"]["notices"]; |
| 234 |
;// CONCATENATED MODULE: ./packages/patterns/build-module/components/create-pattern-modal.js |
| 235 |
|
| 236 |
/** |
| 237 |
* WordPress dependencies |
| 238 |
*/ |
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
const USER_PATTERN_CATEGORY = 'my-patterns'; |
| 245 |
const SYNC_TYPES = { |
| 246 |
full: undefined, |
| 247 |
unsynced: 'unsynced' |
| 248 |
}; |
| 249 |
|
| 250 |
/** |
| 251 |
* Internal dependencies |
| 252 |
*/ |
| 253 |
|
| 254 |
function CreatePatternModal({ |
| 255 |
onSuccess, |
| 256 |
onError, |
| 257 |
clientIds, |
| 258 |
onClose, |
| 259 |
className = 'patterns-menu-items__convert-modal' |
| 260 |
}) { |
| 261 |
const [syncType, setSyncType] = (0,external_wp_element_namespaceObject.useState)(SYNC_TYPES.full); |
| 262 |
const [title, setTitle] = (0,external_wp_element_namespaceObject.useState)(''); |
| 263 |
const { |
| 264 |
__experimentalCreatePattern: createPattern |
| 265 |
} = (0,external_wp_data_namespaceObject.useDispatch)(store); |
| 266 |
const { |
| 267 |
createErrorNotice |
| 268 |
} = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_notices_namespaceObject.store); |
| 269 |
const onCreate = (0,external_wp_element_namespaceObject.useCallback)(async function (patternTitle, sync) { |
| 270 |
try { |
| 271 |
const newPattern = await createPattern(patternTitle, sync, clientIds); |
| 272 |
onSuccess({ |
| 273 |
pattern: newPattern, |
| 274 |
categoryId: USER_PATTERN_CATEGORY |
| 275 |
}); |
| 276 |
} catch (error) { |
| 277 |
createErrorNotice(error.message, { |
| 278 |
type: 'snackbar', |
| 279 |
id: 'convert-to-pattern-error' |
| 280 |
}); |
| 281 |
onError(); |
| 282 |
} |
| 283 |
}, [createPattern, clientIds, onSuccess, createErrorNotice, onError]); |
| 284 |
return (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Modal, { |
| 285 |
title: (0,external_wp_i18n_namespaceObject.__)('Create pattern'), |
| 286 |
onRequestClose: () => { |
| 287 |
onClose(); |
| 288 |
setTitle(''); |
| 289 |
}, |
| 290 |
overlayClassName: className |
| 291 |
}, (0,external_wp_element_namespaceObject.createElement)("form", { |
| 292 |
onSubmit: event => { |
| 293 |
event.preventDefault(); |
| 294 |
onCreate(title, syncType); |
| 295 |
setTitle(''); |
| 296 |
} |
| 297 |
}, (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.__experimentalVStack, { |
| 298 |
spacing: "5" |
| 299 |
}, (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.TextControl, { |
| 300 |
__nextHasNoMarginBottom: true, |
| 301 |
label: (0,external_wp_i18n_namespaceObject.__)('Name'), |
| 302 |
value: title, |
| 303 |
onChange: setTitle, |
| 304 |
placeholder: (0,external_wp_i18n_namespaceObject.__)('My pattern') |
| 305 |
}), (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.ToggleControl, { |
| 306 |
label: (0,external_wp_i18n_namespaceObject.__)('Synced'), |
| 307 |
help: (0,external_wp_i18n_namespaceObject.__)('Editing the pattern will update it anywhere it is used.'), |
| 308 |
checked: !syncType, |
| 309 |
onChange: () => { |
| 310 |
setSyncType(syncType === SYNC_TYPES.full ? SYNC_TYPES.unsynced : SYNC_TYPES.full); |
| 311 |
} |
| 312 |
}), (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.__experimentalHStack, { |
| 313 |
justify: "right" |
| 314 |
}, (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Button, { |
| 315 |
variant: "tertiary", |
| 316 |
onClick: () => { |
| 317 |
onClose(); |
| 318 |
setTitle(''); |
| 319 |
} |
| 320 |
}, (0,external_wp_i18n_namespaceObject.__)('Cancel')), (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Button, { |
| 321 |
variant: "primary", |
| 322 |
type: "submit" |
| 323 |
}, (0,external_wp_i18n_namespaceObject.__)('Create')))))); |
| 324 |
} |
| 325 |
|
| 326 |
;// CONCATENATED MODULE: external ["wp","primitives"] |
| 327 |
const external_wp_primitives_namespaceObject = window["wp"]["primitives"]; |
| 328 |
;// CONCATENATED MODULE: ./packages/icons/build-module/library/symbol.js |
| 329 |
|
| 330 |
/** |
| 331 |
* WordPress dependencies |
| 332 |
*/ |
| 333 |
|
| 334 |
const symbol = (0,external_wp_element_namespaceObject.createElement)(external_wp_primitives_namespaceObject.SVG, { |
| 335 |
xmlns: "http://www.w3.org/2000/svg", |
| 336 |
viewBox: "0 0 24 24" |
| 337 |
}, (0,external_wp_element_namespaceObject.createElement)(external_wp_primitives_namespaceObject.Path, { |
| 338 |
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" |
| 339 |
})); |
| 340 |
/* harmony default export */ const library_symbol = (symbol); |
| 341 |
|
| 342 |
;// CONCATENATED MODULE: ./packages/patterns/build-module/components/pattern-convert-button.js |
| 343 |
|
| 344 |
/** |
| 345 |
* WordPress dependencies |
| 346 |
*/ |
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
/** |
| 357 |
* Internal dependencies |
| 358 |
*/ |
| 359 |
|
| 360 |
|
| 361 |
/** |
| 362 |
* Menu control to convert block(s) to a pattern block. |
| 363 |
* |
| 364 |
* @param {Object} props Component props. |
| 365 |
* @param {string[]} props.clientIds Client ids of selected blocks. |
| 366 |
* @param {string} props.rootClientId ID of the currently selected top-level block. |
| 367 |
* @return {import('@wordpress/element').WPComponent} The menu control or null. |
| 368 |
*/ |
| 369 |
function PatternConvertButton({ |
| 370 |
clientIds, |
| 371 |
rootClientId |
| 372 |
}) { |
| 373 |
const { |
| 374 |
createSuccessNotice |
| 375 |
} = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_notices_namespaceObject.store); |
| 376 |
const [isModalOpen, setIsModalOpen] = (0,external_wp_element_namespaceObject.useState)(false); |
| 377 |
const canConvert = (0,external_wp_data_namespaceObject.useSelect)(select => { |
| 378 |
var _getBlocksByClientId; |
| 379 |
const { |
| 380 |
canUser |
| 381 |
} = select(external_wp_coreData_namespaceObject.store); |
| 382 |
const { |
| 383 |
getBlocksByClientId, |
| 384 |
canInsertBlockType, |
| 385 |
getBlockRootClientId |
| 386 |
} = select(external_wp_blockEditor_namespaceObject.store); |
| 387 |
const rootId = rootClientId || (clientIds.length > 0 ? getBlockRootClientId(clientIds[0]) : undefined); |
| 388 |
const blocks = (_getBlocksByClientId = getBlocksByClientId(clientIds)) !== null && _getBlocksByClientId !== void 0 ? _getBlocksByClientId : []; |
| 389 |
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); |
| 390 |
const _canConvert = |
| 391 |
// Hide when this is already a synced pattern. |
| 392 |
!isReusable && |
| 393 |
// Hide when patterns are disabled. |
| 394 |
canInsertBlockType('core/block', rootId) && blocks.every(block => |
| 395 |
// Guard against the case where a regular block has *just* been converted. |
| 396 |
!!block && |
| 397 |
// Hide on invalid blocks. |
| 398 |
block.isValid && |
| 399 |
// Hide when block doesn't support being made into a pattern. |
| 400 |
(0,external_wp_blocks_namespaceObject.hasBlockSupport)(block.name, 'reusable', true)) && |
| 401 |
// Hide when current doesn't have permission to do that. |
| 402 |
!!canUser('create', 'blocks'); |
| 403 |
return _canConvert; |
| 404 |
}, [clientIds, rootClientId]); |
| 405 |
if (!canConvert) { |
| 406 |
return null; |
| 407 |
} |
| 408 |
const handleSuccess = ({ |
| 409 |
pattern |
| 410 |
}) => { |
| 411 |
createSuccessNotice(pattern.wp_pattern_sync_status === 'unsynced' ? (0,external_wp_i18n_namespaceObject.sprintf)( |
| 412 |
// translators: %s: the name the user has given to the pattern. |
| 413 |
(0,external_wp_i18n_namespaceObject.__)('Unsynced Pattern created: %s'), pattern.title.raw) : (0,external_wp_i18n_namespaceObject.sprintf)( |
| 414 |
// translators: %s: the name the user has given to the pattern. |
| 415 |
(0,external_wp_i18n_namespaceObject.__)('Synced Pattern created: %s'), pattern.title.raw), { |
| 416 |
type: 'snackbar', |
| 417 |
id: 'convert-to-pattern-success' |
| 418 |
}); |
| 419 |
setIsModalOpen(false); |
| 420 |
}; |
| 421 |
return (0,external_wp_element_namespaceObject.createElement)(external_wp_element_namespaceObject.Fragment, null, (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.MenuItem, { |
| 422 |
icon: library_symbol, |
| 423 |
onClick: () => setIsModalOpen(true), |
| 424 |
"aria-expanded": isModalOpen, |
| 425 |
"aria-haspopup": "dialog" |
| 426 |
}, (0,external_wp_i18n_namespaceObject.__)('Create pattern')), isModalOpen && (0,external_wp_element_namespaceObject.createElement)(CreatePatternModal, { |
| 427 |
clientIds: clientIds, |
| 428 |
onSuccess: pattern => { |
| 429 |
handleSuccess(pattern); |
| 430 |
}, |
| 431 |
onError: () => { |
| 432 |
setIsModalOpen(false); |
| 433 |
}, |
| 434 |
onClose: () => { |
| 435 |
setIsModalOpen(false); |
| 436 |
} |
| 437 |
})); |
| 438 |
} |
| 439 |
|
| 440 |
;// CONCATENATED MODULE: external ["wp","url"] |
| 441 |
const external_wp_url_namespaceObject = window["wp"]["url"]; |
| 442 |
;// CONCATENATED MODULE: ./packages/patterns/build-module/components/patterns-manage-button.js |
| 443 |
|
| 444 |
/** |
| 445 |
* WordPress dependencies |
| 446 |
*/ |
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
/** |
| 456 |
* Internal dependencies |
| 457 |
*/ |
| 458 |
|
| 459 |
function PatternsManageButton({ |
| 460 |
clientId |
| 461 |
}) { |
| 462 |
const { |
| 463 |
canRemove, |
| 464 |
isVisible, |
| 465 |
innerBlockCount, |
| 466 |
managePatternsUrl |
| 467 |
} = (0,external_wp_data_namespaceObject.useSelect)(select => { |
| 468 |
const { |
| 469 |
getBlock, |
| 470 |
canRemoveBlock, |
| 471 |
getBlockCount, |
| 472 |
getSettings |
| 473 |
} = select(external_wp_blockEditor_namespaceObject.store); |
| 474 |
const { |
| 475 |
canUser |
| 476 |
} = select(external_wp_coreData_namespaceObject.store); |
| 477 |
const reusableBlock = getBlock(clientId); |
| 478 |
const isBlockTheme = getSettings().__unstableIsBlockBasedTheme; |
| 479 |
return { |
| 480 |
canRemove: canRemoveBlock(clientId), |
| 481 |
isVisible: !!reusableBlock && (0,external_wp_blocks_namespaceObject.isReusableBlock)(reusableBlock) && !!canUser('update', 'blocks', reusableBlock.attributes.ref), |
| 482 |
innerBlockCount: getBlockCount(clientId), |
| 483 |
// The site editor and templates both check whether the user |
| 484 |
// has edit_theme_options capabilities. We can leverage that here |
| 485 |
// and omit the manage patterns link if the user can't access it. |
| 486 |
managePatternsUrl: isBlockTheme && canUser('read', 'templates') ? (0,external_wp_url_namespaceObject.addQueryArgs)('site-editor.php', { |
| 487 |
path: '/patterns' |
| 488 |
}) : (0,external_wp_url_namespaceObject.addQueryArgs)('edit.php', { |
| 489 |
post_type: 'wp_block' |
| 490 |
}) |
| 491 |
}; |
| 492 |
}, [clientId]); |
| 493 |
const { |
| 494 |
__experimentalConvertSyncedPatternToStatic: convertBlockToStatic |
| 495 |
} = (0,external_wp_data_namespaceObject.useDispatch)(store); |
| 496 |
if (!isVisible) { |
| 497 |
return null; |
| 498 |
} |
| 499 |
return (0,external_wp_element_namespaceObject.createElement)(external_wp_element_namespaceObject.Fragment, null, (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.MenuItem, { |
| 500 |
href: managePatternsUrl |
| 501 |
}, (0,external_wp_i18n_namespaceObject.__)('Manage patterns')), canRemove && (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.MenuItem, { |
| 502 |
onClick: () => convertBlockToStatic(clientId) |
| 503 |
}, innerBlockCount > 1 ? (0,external_wp_i18n_namespaceObject.__)('Detach patterns') : (0,external_wp_i18n_namespaceObject.__)('Detach pattern'))); |
| 504 |
} |
| 505 |
/* harmony default export */ const patterns_manage_button = (PatternsManageButton); |
| 506 |
|
| 507 |
;// CONCATENATED MODULE: ./packages/patterns/build-module/components/index.js |
| 508 |
|
| 509 |
/** |
| 510 |
* WordPress dependencies |
| 511 |
*/ |
| 512 |
|
| 513 |
|
| 514 |
/** |
| 515 |
* Internal dependencies |
| 516 |
*/ |
| 517 |
|
| 518 |
|
| 519 |
function PatternsMenuItems({ |
| 520 |
rootClientId |
| 521 |
}) { |
| 522 |
return (0,external_wp_element_namespaceObject.createElement)(external_wp_blockEditor_namespaceObject.BlockSettingsMenuControls, null, ({ |
| 523 |
selectedClientIds |
| 524 |
}) => (0,external_wp_element_namespaceObject.createElement)(external_wp_element_namespaceObject.Fragment, null, (0,external_wp_element_namespaceObject.createElement)(PatternConvertButton, { |
| 525 |
clientIds: selectedClientIds, |
| 526 |
rootClientId: rootClientId |
| 527 |
}), selectedClientIds.length === 1 && (0,external_wp_element_namespaceObject.createElement)(patterns_manage_button, { |
| 528 |
clientId: selectedClientIds[0] |
| 529 |
}))); |
| 530 |
} |
| 531 |
|
| 532 |
;// CONCATENATED MODULE: ./packages/patterns/build-module/private-apis.js |
| 533 |
/** |
| 534 |
* Internal dependencies |
| 535 |
*/ |
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
const privateApis = {}; |
| 540 |
lock(privateApis, { |
| 541 |
CreatePatternModal: CreatePatternModal, |
| 542 |
PatternsMenuItems: PatternsMenuItems |
| 543 |
}); |
| 544 |
|
| 545 |
;// CONCATENATED MODULE: ./packages/patterns/build-module/index.js |
| 546 |
/** |
| 547 |
* Internal dependencies |
| 548 |
*/ |
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
(window.wp = window.wp || {}).patterns = __webpack_exports__; |
| 553 |
/******/ })() |
| 554 |
; |