PluginProbe
PatternsWP – Gutenberg Block Patterns & Page Templates Library / 1.0.4
PatternsWP – Gutenberg Block Patterns & Page Templates Library v1.0.4
trunk 1.0.0 1.0.1 1.0.10 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9
patternswp / build / patternswp-editor.js

patternswp-editor.js in PatternsWP – Gutenberg Block Patterns & Page Templates Library 1.0.4, at build/patternswp-editor.js

1,640 lines 75.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /******/ (() => { // webpackBootstrap
2 /******/ var __webpack_modules__ = ({
3
4 /***/ "./node_modules/@wordpress/icons/build-module/icon/index.js":
5 /*!******************************************************************!*\
6 !*** ./node_modules/@wordpress/icons/build-module/icon/index.js ***!
7 \******************************************************************/
8 /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
9
10 "use strict";
11 __webpack_require__.r(__webpack_exports__);
12 /* harmony export */ __webpack_require__.d(__webpack_exports__, {
13 /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
14 /* harmony export */ });
15 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element");
16 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__);
17 /**
18 * WordPress dependencies
19 */
20
21 /** @typedef {{icon: JSX.Element, size?: number} & import('@wordpress/primitives').SVGProps} IconProps */
22
23 /**
24 * Return an SVG icon.
25 *
26 * @param {IconProps} props icon is the SVG component to render
27 * size is a number specifiying the icon size in pixels
28 * Other props will be passed to wrapped SVG component
29 *
30 * @return {JSX.Element} Icon component
31 */
32
33 function Icon(_ref) {
34 let {
35 icon,
36 size = 24,
37 ...props
38 } = _ref;
39 return (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.cloneElement)(icon, {
40 width: size,
41 height: size,
42 ...props
43 });
44 }
45
46 /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Icon);
47 //# sourceMappingURL=index.js.map
48
49 /***/ }),
50
51 /***/ "./node_modules/@wordpress/icons/build-module/library/block-default.js":
52 /*!*****************************************************************************!*\
53 !*** ./node_modules/@wordpress/icons/build-module/library/block-default.js ***!
54 \*****************************************************************************/
55 /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
56
57 "use strict";
58 __webpack_require__.r(__webpack_exports__);
59 /* harmony export */ __webpack_require__.d(__webpack_exports__, {
60 /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
61 /* harmony export */ });
62 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element");
63 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__);
64 /* harmony import */ var _wordpress_primitives__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/primitives */ "@wordpress/primitives");
65 /* harmony import */ var _wordpress_primitives__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_primitives__WEBPACK_IMPORTED_MODULE_1__);
66
67
68 /**
69 * WordPress dependencies
70 */
71
72 const blockDefault = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_primitives__WEBPACK_IMPORTED_MODULE_1__.SVG, {
73 xmlns: "http://www.w3.org/2000/svg",
74 viewBox: "0 0 24 24"
75 }, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_primitives__WEBPACK_IMPORTED_MODULE_1__.Path, {
76 d: "M19 8h-1V6h-5v2h-2V6H6v2H5c-1.1 0-2 .9-2 2v8c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2v-8c0-1.1-.9-2-2-2zm.5 10c0 .3-.2.5-.5.5H5c-.3 0-.5-.2-.5-.5v-8c0-.3.2-.5.5-.5h14c.3 0 .5.2.5.5v8z"
77 }));
78 /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (blockDefault);
79 //# sourceMappingURL=block-default.js.map
80
81 /***/ }),
82
83 /***/ "./node_modules/@wordpress/icons/build-module/library/category.js":
84 /*!************************************************************************!*\
85 !*** ./node_modules/@wordpress/icons/build-module/library/category.js ***!
86 \************************************************************************/
87 /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
88
89 "use strict";
90 __webpack_require__.r(__webpack_exports__);
91 /* harmony export */ __webpack_require__.d(__webpack_exports__, {
92 /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
93 /* harmony export */ });
94 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element");
95 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__);
96 /* harmony import */ var _wordpress_primitives__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/primitives */ "@wordpress/primitives");
97 /* harmony import */ var _wordpress_primitives__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_primitives__WEBPACK_IMPORTED_MODULE_1__);
98
99
100 /**
101 * WordPress dependencies
102 */
103
104 const category = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_primitives__WEBPACK_IMPORTED_MODULE_1__.SVG, {
105 viewBox: "0 0 24 24",
106 xmlns: "http://www.w3.org/2000/svg"
107 }, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_primitives__WEBPACK_IMPORTED_MODULE_1__.Path, {
108 d: "M6 5.5h3a.5.5 0 01.5.5v3a.5.5 0 01-.5.5H6a.5.5 0 01-.5-.5V6a.5.5 0 01.5-.5zM4 6a2 2 0 012-2h3a2 2 0 012 2v3a2 2 0 01-2 2H6a2 2 0 01-2-2V6zm11-.5h3a.5.5 0 01.5.5v3a.5.5 0 01-.5.5h-3a.5.5 0 01-.5-.5V6a.5.5 0 01.5-.5zM13 6a2 2 0 012-2h3a2 2 0 012 2v3a2 2 0 01-2 2h-3a2 2 0 01-2-2V6zm5 8.5h-3a.5.5 0 00-.5.5v3a.5.5 0 00.5.5h3a.5.5 0 00.5-.5v-3a.5.5 0 00-.5-.5zM15 13a2 2 0 00-2 2v3a2 2 0 002 2h3a2 2 0 002-2v-3a2 2 0 00-2-2h-3zm-9 1.5h3a.5.5 0 01.5.5v3a.5.5 0 01-.5.5H6a.5.5 0 01-.5-.5v-3a.5.5 0 01.5-.5zM4 15a2 2 0 012-2h3a2 2 0 012 2v3a2 2 0 01-2 2H6a2 2 0 01-2-2v-3z",
109 fillRule: "evenodd",
110 clipRule: "evenodd"
111 }));
112 /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (category);
113 //# sourceMappingURL=category.js.map
114
115 /***/ }),
116
117 /***/ "./node_modules/@wordpress/icons/build-module/library/check.js":
118 /*!*********************************************************************!*\
119 !*** ./node_modules/@wordpress/icons/build-module/library/check.js ***!
120 \*********************************************************************/
121 /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
122
123 "use strict";
124 __webpack_require__.r(__webpack_exports__);
125 /* harmony export */ __webpack_require__.d(__webpack_exports__, {
126 /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
127 /* harmony export */ });
128 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element");
129 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__);
130 /* harmony import */ var _wordpress_primitives__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/primitives */ "@wordpress/primitives");
131 /* harmony import */ var _wordpress_primitives__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_primitives__WEBPACK_IMPORTED_MODULE_1__);
132
133
134 /**
135 * WordPress dependencies
136 */
137
138 const check = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_primitives__WEBPACK_IMPORTED_MODULE_1__.SVG, {
139 xmlns: "http://www.w3.org/2000/svg",
140 viewBox: "0 0 24 24"
141 }, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_primitives__WEBPACK_IMPORTED_MODULE_1__.Path, {
142 d: "M16.7 7.1l-6.3 8.5-3.3-2.5-.9 1.2 4.5 3.4L17.9 8z"
143 }));
144 /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (check);
145 //# sourceMappingURL=check.js.map
146
147 /***/ }),
148
149 /***/ "./node_modules/@wordpress/icons/build-module/library/stretch-full-width.js":
150 /*!**********************************************************************************!*\
151 !*** ./node_modules/@wordpress/icons/build-module/library/stretch-full-width.js ***!
152 \**********************************************************************************/
153 /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
154
155 "use strict";
156 __webpack_require__.r(__webpack_exports__);
157 /* harmony export */ __webpack_require__.d(__webpack_exports__, {
158 /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
159 /* harmony export */ });
160 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element");
161 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__);
162 /* harmony import */ var _wordpress_primitives__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/primitives */ "@wordpress/primitives");
163 /* harmony import */ var _wordpress_primitives__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_primitives__WEBPACK_IMPORTED_MODULE_1__);
164
165
166 /**
167 * WordPress dependencies
168 */
169
170 const stretchFullWidth = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_primitives__WEBPACK_IMPORTED_MODULE_1__.SVG, {
171 xmlns: "http://www.w3.org/2000/svg",
172 viewBox: "0 0 24 24"
173 }, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_primitives__WEBPACK_IMPORTED_MODULE_1__.Path, {
174 d: "M5 4v11h14V4H5zm3 15.8h8v-1.5H8v1.5z"
175 }));
176 /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (stretchFullWidth);
177 //# sourceMappingURL=stretch-full-width.js.map
178
179 /***/ }),
180
181 /***/ "./src/core-components/inserter-listbox/context.js":
182 /*!*********************************************************!*\
183 !*** ./src/core-components/inserter-listbox/context.js ***!
184 \*********************************************************/
185 /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
186
187 "use strict";
188 __webpack_require__.r(__webpack_exports__);
189 /* harmony export */ __webpack_require__.d(__webpack_exports__, {
190 /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
191 /* harmony export */ });
192 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element");
193 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__);
194 /**
195 * WordPress dependencies
196 */
197
198 const InserterListboxContext = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createContext)();
199 /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (InserterListboxContext);
200
201 /***/ }),
202
203 /***/ "./src/core-components/inserter-listbox/index.js":
204 /*!*******************************************************!*\
205 !*** ./src/core-components/inserter-listbox/index.js ***!
206 \*******************************************************/
207 /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
208
209 "use strict";
210 __webpack_require__.r(__webpack_exports__);
211 /* harmony export */ __webpack_require__.d(__webpack_exports__, {
212 /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
213 /* harmony export */ });
214 /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
215 /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
216 /* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/components */ "@wordpress/components");
217 /* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_components__WEBPACK_IMPORTED_MODULE_1__);
218 /* harmony import */ var _context__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./context */ "./src/core-components/inserter-listbox/context.js");
219
220 /**
221 * WordPress dependencies
222 */
223 // eslint-disable-line
224
225 /**
226 * Internal dependencies
227 */
228
229 function InserterListbox({
230 children
231 }) {
232 const compositeState = (0,_wordpress_components__WEBPACK_IMPORTED_MODULE_1__.__unstableUseCompositeState)({
233 shift: true,
234 wrap: 'horizontal'
235 });
236 return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_context__WEBPACK_IMPORTED_MODULE_2__["default"].Provider, {
237 value: compositeState
238 }, children);
239 }
240 /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (InserterListbox);
241
242 /***/ }),
243
244 /***/ "./src/core-components/no-results.js":
245 /*!*******************************************!*\
246 !*** ./src/core-components/no-results.js ***!
247 \*******************************************/
248 /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
249
250 "use strict";
251 __webpack_require__.r(__webpack_exports__);
252 /* harmony export */ __webpack_require__.d(__webpack_exports__, {
253 /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
254 /* harmony export */ });
255 /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
256 /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
257 /* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n");
258 /* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__);
259 /* harmony import */ var _wordpress_icons__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/icons */ "./node_modules/@wordpress/icons/build-module/icon/index.js");
260 /* harmony import */ var _wordpress_icons__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/icons */ "./node_modules/@wordpress/icons/build-module/library/block-default.js");
261
262 /**
263 * WordPress dependencies
264 */
265
266
267 function InserterNoResults({
268 icon,
269 label
270 }) {
271 return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
272 className: "patternswp-inserter__no-results"
273 }, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_icons__WEBPACK_IMPORTED_MODULE_2__["default"], {
274 className: "patternswp-inserter__no-results-icon",
275 icon: icon ? icon : _wordpress_icons__WEBPACK_IMPORTED_MODULE_3__["default"]
276 }), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("p", null, label ? label : (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)('No results found.', 'patternswp'))));
277 }
278 /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (InserterNoResults);
279
280 /***/ }),
281
282 /***/ "./src/core-hooks/use-insertion-point.js":
283 /*!***********************************************!*\
284 !*** ./src/core-hooks/use-insertion-point.js ***!
285 \***********************************************/
286 /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
287
288 "use strict";
289 __webpack_require__.r(__webpack_exports__);
290 /* harmony export */ __webpack_require__.d(__webpack_exports__, {
291 /* harmony export */ "default": () => (/* binding */ useInsertionPoint)
292 /* harmony export */ });
293 /* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! lodash */ "lodash");
294 /* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_0__);
295 /* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data");
296 /* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_1__);
297 /* harmony import */ var _wordpress_blocks__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/blocks */ "@wordpress/blocks");
298 /* harmony import */ var _wordpress_blocks__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_blocks__WEBPACK_IMPORTED_MODULE_2__);
299 /* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n");
300 /* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_3__);
301 /* harmony import */ var _wordpress_a11y__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/a11y */ "@wordpress/a11y");
302 /* harmony import */ var _wordpress_a11y__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_a11y__WEBPACK_IMPORTED_MODULE_4__);
303 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element");
304 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_5__);
305 /* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! @wordpress/block-editor */ "@wordpress/block-editor");
306 /* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_6__);
307 /**
308 * External dependencies
309 */
310
311
312 /**
313 * WordPress dependencies
314 */
315
316
317
318
319
320
321
322 /**
323 * @typedef WPInserterConfig
324 * @property {string=} rootClientId If set, insertion will be into the block with this ID.
325 * @property {number=} insertionIndex If set, insertion will be into this explicit position.
326 * @property {string=} clientId If set, insertion will be after the block with this ID.
327 * @property {boolean=} isAppender Whether the inserter is an appender or not.
328 * @property {Function=} onSelect Called after insertion.
329 */
330
331 /**
332 * Returns the insertion point state given the inserter config.
333 *
334 * @param {WPInserterConfig} config Inserter Config.
335 * @return {Array} Insertion Point State (rootClientID, onInsertBlocks and onToggle).
336 */
337 function useInsertionPoint({
338 rootClientId = '',
339 insertionIndex,
340 clientId,
341 isAppender,
342 onSelect,
343 shouldFocusBlock = true
344 }) {
345 const {
346 getSelectedBlock
347 } = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_1__.useSelect)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_6__.store);
348 const {
349 destinationRootClientId,
350 destinationIndex
351 } = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_1__.useSelect)(select => {
352 const {
353 getSelectedBlockClientId,
354 getBlockRootClientId,
355 getBlockIndex,
356 getBlockOrder
357 } = select(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_6__.store);
358 const selectedBlockClientId = getSelectedBlockClientId();
359 let _destinationRootClientId = rootClientId;
360 let _destinationIndex;
361 if (insertionIndex !== undefined) {
362 // Insert into a specific index.
363 _destinationIndex = insertionIndex;
364 } else if (clientId) {
365 // Insert after a specific client ID.
366 _destinationIndex = getBlockIndex(clientId, _destinationRootClientId);
367 } else if (!isAppender && selectedBlockClientId) {
368 _destinationRootClientId = getBlockRootClientId(selectedBlockClientId);
369 _destinationIndex = getBlockIndex(selectedBlockClientId, _destinationRootClientId) + 1;
370 } else {
371 // Insert at the end of the list.
372 _destinationIndex = getBlockOrder(_destinationRootClientId).length;
373 }
374 return {
375 destinationRootClientId: _destinationRootClientId,
376 destinationIndex: _destinationIndex
377 };
378 }, [rootClientId, insertionIndex, clientId, isAppender]);
379 const {
380 replaceBlocks,
381 insertBlocks,
382 showInsertionPoint,
383 hideInsertionPoint
384 } = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_1__.useDispatch)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_6__.store);
385 const onInsertBlocks = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_5__.useCallback)((blocks, meta, shouldForceFocusBlock = false) => {
386 const selectedBlock = getSelectedBlock();
387 if (!isAppender && selectedBlock && (0,_wordpress_blocks__WEBPACK_IMPORTED_MODULE_2__.isUnmodifiedDefaultBlock)(selectedBlock)) {
388 replaceBlocks(selectedBlock.clientId, blocks, null, shouldFocusBlock || shouldForceFocusBlock ? 0 : null, meta);
389 } else {
390 insertBlocks(blocks, destinationIndex, destinationRootClientId, true, shouldFocusBlock || shouldForceFocusBlock ? 0 : null, meta);
391 }
392 const message = (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_3__.sprintf)(
393 // translators: %d: the name of the block that has been added
394 (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_3__._n)('%d block added.', '%d blocks added.', (0,lodash__WEBPACK_IMPORTED_MODULE_0__.castArray)(blocks).length), (0,lodash__WEBPACK_IMPORTED_MODULE_0__.castArray)(blocks).length);
395 (0,_wordpress_a11y__WEBPACK_IMPORTED_MODULE_4__.speak)(message);
396 if (onSelect) {
397 onSelect();
398 }
399 }, [isAppender, getSelectedBlock, replaceBlocks, insertBlocks, destinationRootClientId, destinationIndex, onSelect, shouldFocusBlock]);
400 const onToggleInsertionPoint = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_5__.useCallback)(show => {
401 if (show) {
402 showInsertionPoint(destinationRootClientId, destinationIndex);
403 } else {
404 hideInsertionPoint();
405 }
406 }, [showInsertionPoint, hideInsertionPoint, destinationRootClientId, destinationIndex]);
407 return [destinationRootClientId, onInsertBlocks, onToggleInsertionPoint];
408 }
409
410 /***/ }),
411
412 /***/ "./src/core-hooks/use-patterns-state.js":
413 /*!**********************************************!*\
414 !*** ./src/core-hooks/use-patterns-state.js ***!
415 \**********************************************/
416 /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
417
418 "use strict";
419 __webpack_require__.r(__webpack_exports__);
420 /* harmony export */ __webpack_require__.d(__webpack_exports__, {
421 /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
422 /* harmony export */ });
423 /* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! lodash */ "lodash");
424 /* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_0__);
425 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element");
426 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__);
427 /* harmony import */ var _wordpress_blocks__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/blocks */ "@wordpress/blocks");
428 /* harmony import */ var _wordpress_blocks__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_blocks__WEBPACK_IMPORTED_MODULE_2__);
429 /* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data");
430 /* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_3__);
431 /* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n");
432 /* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__);
433 /* harmony import */ var _wordpress_notices__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @wordpress/notices */ "@wordpress/notices");
434 /* harmony import */ var _wordpress_notices__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_wordpress_notices__WEBPACK_IMPORTED_MODULE_5__);
435 /* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! @wordpress/block-editor */ "@wordpress/block-editor");
436 /* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_6__);
437 /**
438 * External dependencies
439 */
440
441
442 /**
443 * WordPress dependencies
444 */
445
446
447
448
449
450
451
452 /**
453 * Retrieves the block patterns inserter state.
454 *
455 * @param {Function} onInsert function called when inserter a list of blocks.
456 * @param {string=} rootClientId Insertion's root client ID.
457 *
458 * @return {Array} Returns the patterns state. (patterns, categories, onSelect handler)
459 */
460 const usePatternsState = (onInsert, rootClientId) => {
461 const {
462 patterns,
463 patternCategories,
464 patternCategoryTypes
465 } = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_3__.useSelect)(select => {
466 var _categoryTypes$patter;
467 const {
468 __experimentalGetAllowedPatterns,
469 getSettings
470 } = select(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_6__.store);
471
472 // Fetch any register pattern category types with the custom REST
473 // API endpoint. Eventually replace with core functionality.
474 const {
475 getEntityRecord
476 } = select('core');
477 const categoryTypes = getEntityRecord('patternswp/v1', 'patternCategoryTypes');
478 return {
479 patterns: __experimentalGetAllowedPatterns(rootClientId),
480 patternCategories: getSettings().__experimentalBlockPatternCategories,
481 patternCategoryTypes: (_categoryTypes$patter = categoryTypes?.patternCategoryTypes) !== null && _categoryTypes$patter !== void 0 ? _categoryTypes$patter : 'fetching'
482 // This is new functionality and will need to ultimately be added to the
483 // Gutenberg Patterns API. Category Types allow theme/plugin developers to
484 // group pattern categories together in the new Pattern Explorer.
485 // patternCategoryTypes: getSettings().__experimentalBlockPatternCategoryTypes,
486 };
487 }, [rootClientId]);
488 const {
489 createSuccessNotice
490 } = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_3__.useDispatch)(_wordpress_notices__WEBPACK_IMPORTED_MODULE_5__.store);
491 const onClickPattern = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.useCallback)((pattern, blocks) => {
492 onInsert((0,lodash__WEBPACK_IMPORTED_MODULE_0__.map)(blocks, block => (0,_wordpress_blocks__WEBPACK_IMPORTED_MODULE_2__.cloneBlock)(block)), pattern.name);
493 createSuccessNotice((0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.sprintf)( /* translators: %s: block pattern title. */
494 (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)('Block pattern "%s" inserted.', 'patternswp'), pattern.title), {
495 type: 'snackbar'
496 });
497 }, []);
498 return [patterns, patternCategories, patternCategoryTypes, onClickPattern];
499 };
500 /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (usePatternsState);
501
502 /***/ }),
503
504 /***/ "./src/pattern-explorer.js":
505 /*!*********************************!*\
506 !*** ./src/pattern-explorer.js ***!
507 \*********************************/
508 /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
509
510 "use strict";
511 __webpack_require__.r(__webpack_exports__);
512 /* harmony export */ __webpack_require__.d(__webpack_exports__, {
513 /* harmony export */ "default": () => (/* binding */ PatternExplorer)
514 /* harmony export */ });
515 /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
516 /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
517 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element");
518 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__);
519 /* harmony import */ var _sidebar__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./sidebar */ "./src/sidebar.js");
520 /* harmony import */ var _preview__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./preview */ "./src/preview/index.js");
521
522 /**
523 * WordPress dependencies
524 */
525
526
527 /**
528 * Internal dependencies
529 */
530
531
532
533 /**
534 * Render the block pattern inserter.
535 *
536 * @since 0.1.0
537 * @param {Object} props All the props passed to this function
538 * @return {string} Return the rendered JSX
539 */
540 function PatternExplorer(props) {
541 const {
542 allPatterns,
543 initialCategory,
544 patternCategories,
545 patternCategoryTypes
546 } = props;
547 const [selectedCategory, setSelectedCategory] = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.useState)(initialCategory?.name);
548 const [searchValue, setSearchValue] = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.useState)('');
549 return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
550 className: "patternswp"
551 }, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_sidebar__WEBPACK_IMPORTED_MODULE_2__["default"], {
552 patternCategories: patternCategories,
553 patternCategoryTypes: patternCategoryTypes,
554 selectedCategory: selectedCategory,
555 setSelectedCategory: setSelectedCategory,
556 searchValue: searchValue,
557 setSearchValue: setSearchValue
558 }), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_preview__WEBPACK_IMPORTED_MODULE_3__["default"], {
559 allPatterns: allPatterns,
560 patternCategories: patternCategories,
561 selectedCategory: selectedCategory,
562 searchValue: searchValue,
563 onRequestClose: props.onRequestClose
564 }));
565 }
566
567 /***/ }),
568
569 /***/ "./src/preview/header.js":
570 /*!*******************************!*\
571 !*** ./src/preview/header.js ***!
572 \*******************************/
573 /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
574
575 "use strict";
576 __webpack_require__.r(__webpack_exports__);
577 /* harmony export */ __webpack_require__.d(__webpack_exports__, {
578 /* harmony export */ "default": () => (/* binding */ PreviewHeader)
579 /* harmony export */ });
580 /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
581 /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
582 /* harmony import */ var classnames__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! classnames */ "./node_modules/classnames/index.js");
583 /* harmony import */ var classnames__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(classnames__WEBPACK_IMPORTED_MODULE_1__);
584 /* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n");
585 /* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__);
586 /* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/components */ "@wordpress/components");
587 /* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__);
588 /* harmony import */ var _wordpress_icons__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/icons */ "./node_modules/@wordpress/icons/build-module/library/check.js");
589 /* harmony import */ var _wordpress_icons__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @wordpress/icons */ "./node_modules/@wordpress/icons/build-module/library/stretch-full-width.js");
590 /* harmony import */ var _wordpress_icons__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! @wordpress/icons */ "./node_modules/@wordpress/icons/build-module/library/category.js");
591
592 /**
593 * External dependencies
594 */
595
596
597 /**
598 * WordPress dependencies
599 */
600
601
602
603
604 /**
605 * Renders the block pattern preview header.
606 *
607 * @since 0.1.0
608 * @param {Object} props All the props passed to this function
609 * @return {string} Return the rendered JSX
610 */
611 function PreviewHeader(props) {
612 const {
613 viewportWidth,
614 setViewportWidth,
615 isGrid,
616 setIsGrid,
617 shownPatterns,
618 searchValue,
619 isLoading
620 } = props;
621 const widths = [{
622 label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__.__)('Desktop', 'patternswp'),
623 slug: 'desktop',
624 value: 1300,
625 active: viewportWidth === 1300
626 }, {
627 label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__.__)('Tablet', 'patternswp'),
628 slug: 'tablet',
629 value: 778,
630 active: viewportWidth === 778
631 }, {
632 label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__.__)('Mobile', 'patternswp'),
633 slug: 'mobile',
634 value: 358,
635 active: viewportWidth === 358
636 }];
637 function toggleWidths(width) {
638 if (!width.active) {
639 setViewportWidth(width.value);
640 }
641 }
642 const baseClassName = 'patternswp__preview-header';
643 return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
644 className: baseClassName
645 }, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
646 className: `${baseClassName}__search-results`
647 }, isLoading && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.Spinner, null), searchValue && searchValue.length > 1 && (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__.sprintf)(
648 // translators: %1$d: Number of patterns. %2$s: The search input.
649 (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__._n)('%1$d search result for "%2$s"', '%1$d search results for "%2$s"', shownPatterns.length, 'patternswp'), shownPatterns.length, searchValue)), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
650 className: `${baseClassName}__controls`
651 }, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.DropdownMenu, {
652 icon: '',
653 text: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__.__)('Preview', 'patternswp'),
654 className: "viewport-toggle",
655 toggleProps: {
656 isTertiary: true
657 },
658 popoverProps: {
659 focusOnMount: 'container',
660 position: 'bottom left'
661 }
662 }, () => (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.MenuGroup, null, widths.map(width => (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.MenuItem, {
663 key: width.slug,
664 className: classnames__WEBPACK_IMPORTED_MODULE_1___default()({
665 disabled: !width.active
666 }),
667 icon: width.active ? _wordpress_icons__WEBPACK_IMPORTED_MODULE_4__["default"] : '',
668 onClick: () => toggleWidths(width)
669 }, width.label)))), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.Button, {
670 label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__.__)('Individual Pattern', 'patternswp'),
671 icon: _wordpress_icons__WEBPACK_IMPORTED_MODULE_5__["default"],
672 isPressed: !isGrid,
673 onClick: () => setIsGrid(!isGrid)
674 }), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.Button, {
675 label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__.__)('Grid View', 'patternswp'),
676 icon: _wordpress_icons__WEBPACK_IMPORTED_MODULE_6__["default"],
677 isPressed: isGrid,
678 onClick: () => setIsGrid(!isGrid)
679 })));
680 }
681
682 /***/ }),
683
684 /***/ "./src/preview/index.js":
685 /*!******************************!*\
686 !*** ./src/preview/index.js ***!
687 \******************************/
688 /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
689
690 "use strict";
691 __webpack_require__.r(__webpack_exports__);
692 /* harmony export */ __webpack_require__.d(__webpack_exports__, {
693 /* harmony export */ "default": () => (/* binding */ PatternExplorerPreview)
694 /* harmony export */ });
695 /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
696 /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
697 /* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! lodash */ "lodash");
698 /* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_1__);
699 /* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n");
700 /* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__);
701 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element");
702 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_3__);
703 /* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/compose */ "@wordpress/compose");
704 /* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_compose__WEBPACK_IMPORTED_MODULE_4__);
705 /* harmony import */ var _wordpress_a11y__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @wordpress/a11y */ "@wordpress/a11y");
706 /* harmony import */ var _wordpress_a11y__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_wordpress_a11y__WEBPACK_IMPORTED_MODULE_5__);
707 /* harmony import */ var _header__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./header */ "./src/preview/header.js");
708 /* harmony import */ var _pattern_list__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./pattern-list */ "./src/preview/pattern-list.js");
709
710 /**
711 * External dependencies
712 */
713
714
715 /**
716 * WordPress dependencies
717 */
718
719
720
721
722
723 /**
724 * Internal dependencies
725 */
726
727
728 const INITIAL_INSERTER_RESULTS = 3;
729
730 /**
731 * Renders the grid of block pattern previews.
732 *
733 * @since 0.1.0
734 * @param {Object} props All the props passed to this function
735 * @return {string} Return the rendered JSX
736 */
737 function PatternExplorerPreview(props) {
738 const {
739 allPatterns,
740 patternCategories,
741 selectedCategory,
742 searchValue
743 } = props;
744 const [viewportWidth, setViewportWidth] = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_3__.useState)(1300);
745 const [isGrid, setIsGrid] = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_3__.useState)(true);
746 const debouncedSpeak = (0,_wordpress_compose__WEBPACK_IMPORTED_MODULE_4__.useDebounce)(_wordpress_a11y__WEBPACK_IMPORTED_MODULE_5__.speak, 500);
747 const registeredPatternCategories = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_3__.useMemo)(() => patternCategories.map(patternCategory => patternCategory.name), [patternCategories]);
748 const filteredPatterns = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_3__.useMemo)(() => {
749 let results = [];
750
751 // Only start searching after the user has typed 2+ letters.
752 const isSearching = searchValue && searchValue.length > 1;
753 if (isSearching) {
754 results = allPatterns.filter(pattern => {
755 const input = searchValue.toLowerCase();
756 const title = pattern.title.toLowerCase();
757
758 // First check if the title matches.
759 if (title.includes(input)) {
760 return true;
761 }
762
763 // Then check if any keywords match.
764 if (pattern?.keywords && Array.isArray(pattern.keywords)) {
765 const keywordMatches = pattern.keywords.filter(keyword => typeof keyword === 'string' && keyword.includes(input));
766 return !(0,lodash__WEBPACK_IMPORTED_MODULE_1__.isEmpty)(keywordMatches);
767 }
768 return false;
769 }).filter(pattern => {
770 // Only include patterns with categories starting with 'patternswp-'
771 return pattern.categories?.some(category => category.startsWith('patternswp-'));
772 });
773 } else {
774 // Filter patterns based on the selected category.
775 if (selectedCategory === 'all') {
776 results = allPatterns.filter(pattern => {
777 return pattern.categories && pattern.categories.some(category => category.startsWith('patternswp-'));
778 });
779 } else if (selectedCategory === 'uncategorized') {
780 results = allPatterns.filter(pattern => !pattern.categories || pattern.categories.length === 0);
781 } else {
782 results = allPatterns.filter(pattern => pattern.categories?.includes(selectedCategory));
783 }
784 }
785 return results;
786 }, [searchValue, selectedCategory, allPatterns]);
787 const shownPatterns = (0,_wordpress_compose__WEBPACK_IMPORTED_MODULE_4__.useAsyncList)(filteredPatterns, {
788 step: INITIAL_INSERTER_RESULTS
789 });
790
791 // Are patterns still being loaded?
792 const isLoading = shownPatterns.length < filteredPatterns.length;
793
794 // Announce search results on change and only when loading is finished.
795 // TODO: This needs work, not updating when search field is cleared.
796 (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_3__.useEffect)(() => {
797 if (!searchValue || isLoading) {
798 return;
799 }
800 const count = filteredPatterns.length;
801 const resultsFoundMessage = (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__.sprintf)( /* translators: %d: number of patterns found. */
802 (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__._n)('%d pattern found.', '%d patterns found.', count, 'patternswp'), count);
803 debouncedSpeak(resultsFoundMessage);
804 }, [searchValue, debouncedSpeak]);
805 const baseClassName = 'patternswp__preview';
806 return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
807 className: baseClassName
808 }, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_header__WEBPACK_IMPORTED_MODULE_6__["default"], {
809 viewportWidth: viewportWidth,
810 setViewportWidth: setViewportWidth,
811 isGrid: isGrid,
812 setIsGrid: setIsGrid,
813 shownPatterns: shownPatterns,
814 searchValue: searchValue,
815 isLoading: isLoading
816 }), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_pattern_list__WEBPACK_IMPORTED_MODULE_7__["default"], {
817 viewportWidth: viewportWidth,
818 isGrid: isGrid,
819 shownPatterns: shownPatterns,
820 searchValue: searchValue,
821 isLoading: isLoading,
822 onRequestClose: props.onRequestClose
823 }));
824 }
825
826 /***/ }),
827
828 /***/ "./src/preview/pattern-list.js":
829 /*!*************************************!*\
830 !*** ./src/preview/pattern-list.js ***!
831 \*************************************/
832 /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
833
834 "use strict";
835 __webpack_require__.r(__webpack_exports__);
836 /* harmony export */ __webpack_require__.d(__webpack_exports__, {
837 /* harmony export */ "default": () => (/* binding */ PreviewPatternList)
838 /* harmony export */ });
839 /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
840 /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
841 /* harmony import */ var classnames__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! classnames */ "./node_modules/classnames/index.js");
842 /* harmony import */ var classnames__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(classnames__WEBPACK_IMPORTED_MODULE_1__);
843 /* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! lodash */ "lodash");
844 /* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_2__);
845 /* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n");
846 /* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_3__);
847 /* harmony import */ var _wordpress_icons__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! @wordpress/icons */ "./node_modules/@wordpress/icons/build-module/library/category.js");
848 /* harmony import */ var _wordpress_icons__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! @wordpress/icons */ "./node_modules/@wordpress/icons/build-module/library/stretch-full-width.js");
849 /* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/components */ "@wordpress/components");
850 /* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__);
851 /* harmony import */ var _core_components_no_results__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./../core-components/no-results */ "./src/core-components/no-results.js");
852 /* harmony import */ var _core_components_inserter_listbox__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./../core-components/inserter-listbox */ "./src/core-components/inserter-listbox/index.js");
853 /* harmony import */ var _core_hooks_use_insertion_point__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./../core-hooks/use-insertion-point */ "./src/core-hooks/use-insertion-point.js");
854 /* harmony import */ var _pattern__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./pattern */ "./src/preview/pattern.js");
855
856 /**
857 * External dependencies
858 */
859
860
861
862 /**
863 * WordPress dependencies
864 */
865
866
867
868 /**
869 * Internal dependencies
870 */
871
872
873
874
875
876 /**
877 * Renders the grid of block pattern previews.
878 *
879 * @since 0.1.0
880 * @param {Object} props All the props passed to this function
881 * @return {string} Return the rendered JSX
882 */
883 function PreviewPatternList(props) {
884 const {
885 isGrid,
886 isLoading,
887 searchValue,
888 shownPatterns,
889 viewportWidth
890 } = props;
891 const [destinationRootClientId, onInsertBlocks] = (0,_core_hooks_use_insertion_point__WEBPACK_IMPORTED_MODULE_7__["default"])({
892 // eslint-disable-line
893 shouldFocusBlock: true
894 });
895 const isError = (0,lodash__WEBPACK_IMPORTED_MODULE_2__.isEmpty)(shownPatterns) && !searchValue && !isLoading;
896 const noSearchResults = (0,lodash__WEBPACK_IMPORTED_MODULE_2__.isEmpty)(shownPatterns) && searchValue;
897 const hasPatterns = !isError && !noSearchResults;
898 const noPatternsMessage = !hasPatterns && noSearchResults ? (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_3__.__)('No search results found.', 'patternswp') : (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_3__.__)('No patterns were found for this category.', 'patternswp');
899 const composite = (0,_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.__unstableUseCompositeState)();
900 const baseClassName = 'patternswp__preview-pattern-list';
901 return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_core_components_inserter_listbox__WEBPACK_IMPORTED_MODULE_6__["default"], null, !hasPatterns && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_core_components_no_results__WEBPACK_IMPORTED_MODULE_5__["default"], {
902 icon: isGrid ? _wordpress_icons__WEBPACK_IMPORTED_MODULE_9__["default"] : _wordpress_icons__WEBPACK_IMPORTED_MODULE_10__["default"],
903 label: noPatternsMessage
904 }), hasPatterns && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.__unstableComposite, {
905 ...composite,
906 role: "listbox",
907 className: classnames__WEBPACK_IMPORTED_MODULE_1___default()(baseClassName, {
908 'is-grid': isGrid,
909 'is-loading': isLoading,
910 // TODO this needs reworking.
911 'preview-tablet': viewportWidth === 778,
912 'preview-mobile': viewportWidth === 358
913 }),
914 "aria-label": (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_3__.__)('Patterns', 'patternswp')
915 }, shownPatterns.map(pattern => (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_pattern__WEBPACK_IMPORTED_MODULE_8__["default"], {
916 key: pattern.name,
917 pattern: pattern,
918 onInsertPattern: onInsertBlocks,
919 viewportWidth: viewportWidth,
920 composite: composite,
921 onRequestClose: props.onRequestClose
922 }))));
923 }
924
925 /***/ }),
926
927 /***/ "./src/preview/pattern.js":
928 /*!********************************!*\
929 !*** ./src/preview/pattern.js ***!
930 \********************************/
931 /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
932
933 "use strict";
934 __webpack_require__.r(__webpack_exports__);
935 /* harmony export */ __webpack_require__.d(__webpack_exports__, {
936 /* harmony export */ "default": () => (/* binding */ Pattern)
937 /* harmony export */ });
938 /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
939 /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
940 /* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n");
941 /* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__);
942 /* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/components */ "@wordpress/components");
943 /* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_components__WEBPACK_IMPORTED_MODULE_2__);
944 /* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/block-editor */ "@wordpress/block-editor");
945 /* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3__);
946 /* harmony import */ var _wordpress_blocks__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/blocks */ "@wordpress/blocks");
947 /* harmony import */ var _wordpress_blocks__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_blocks__WEBPACK_IMPORTED_MODULE_4__);
948 /* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @wordpress/compose */ "@wordpress/compose");
949 /* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_wordpress_compose__WEBPACK_IMPORTED_MODULE_5__);
950 /* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data");
951 /* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_6__);
952
953 /**
954 * WordPress dependencies
955 */
956
957
958
959
960
961
962
963 /**
964 * Renders the block pattern 'card'.
965 *
966 * @since 0.1.0
967 * @param {Object} props All the props passed to this function
968 * @return {string} Return the rendered JSX
969 */
970 function Pattern(props) {
971 const {
972 pattern,
973 onInsertPattern,
974 viewportWidth,
975 composite,
976 isBlock,
977 clientId
978 } = props;
979 const {
980 title,
981 categories = [],
982 blocks
983 } = pattern; // eslint-disable-line
984 const {
985 createSuccessNotice
986 } = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_6__.useDispatch)('core/notices');
987 const instanceId = (0,_wordpress_compose__WEBPACK_IMPORTED_MODULE_5__.useInstanceId)(Pattern);
988 const descriptionId = `preview-pattern-card__info-description-${instanceId}`;
989 function insertPattern() {
990 onInsertPattern(blocks.map(block => (0,_wordpress_blocks__WEBPACK_IMPORTED_MODULE_4__.cloneBlock)(block)));
991
992 // If the inserter was rendered from a block, we need to remove that
993 // original block.
994 if (isBlock) {
995 (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_6__.dispatch)('core/block-editor').removeBlock(clientId);
996 }
997 createSuccessNotice((0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.sprintf)(
998 // Translators: Name of the pattern being inserted.
999 (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)('Block pattern "%s" inserted.', 'patternswp'), pattern.title), {
1000 type: 'snackbar'
1001 });
1002 props.onRequestClose();
1003 }
1004 const baseClassName = 'patternswp__preview-pattern-list__item';
1005 return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
1006 className: baseClassName,
1007 "aria-label": pattern.title,
1008 "aria-describedby": pattern?.description ? descriptionId : undefined
1009 }, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_2__.__unstableCompositeItem, {
1010 role: "option",
1011 as: "div",
1012 ...composite,
1013 className: `${baseClassName}-preview`,
1014 onClick: insertPattern
1015 }, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3__.BlockPreview, {
1016 blocks: blocks,
1017 viewportWidth: viewportWidth
1018 })), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
1019 className: `${baseClassName}-actions`
1020 }, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
1021 className: `${baseClassName}-title`
1022 }, title), !!pattern.description && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_2__.VisuallyHidden, {
1023 id: descriptionId
1024 }, pattern.description), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_2__.Button, {
1025 isSecondary: true,
1026 onClick: insertPattern
1027 }, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)('Add Pattern', 'patternswp'))));
1028 }
1029
1030 /***/ }),
1031
1032 /***/ "./src/sidebar.js":
1033 /*!************************!*\
1034 !*** ./src/sidebar.js ***!
1035 \************************/
1036 /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
1037
1038 "use strict";
1039 __webpack_require__.r(__webpack_exports__);
1040 /* harmony export */ __webpack_require__.d(__webpack_exports__, {
1041 /* harmony export */ "default": () => (/* binding */ PatternExplorerSidebar)
1042 /* harmony export */ });
1043 /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
1044 /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
1045 /* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n");
1046 /* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__);
1047 /* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/components */ "@wordpress/components");
1048 /* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_components__WEBPACK_IMPORTED_MODULE_2__);
1049 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element");
1050 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_3__);
1051
1052 /**
1053 * WordPress dependencies
1054 */
1055
1056
1057
1058
1059 /**
1060 * Renders the block pattern category sidebar control.
1061 *
1062 * @since 0.1.0
1063 * @param {Object} props All the props passed to this function
1064 * @return {string} Return the rendered JSX
1065 */
1066 function PatternExplorerSidebar(props) {
1067 const {
1068 patternCategories,
1069 patternCategoryTypes,
1070 selectedCategory,
1071 setSelectedCategory,
1072 searchValue,
1073 setSearchValue
1074 } = props;
1075 function onClickCategory(category) {
1076 setSelectedCategory(category);
1077 setSearchValue('');
1078 }
1079 const registeredCategoryTypes = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_3__.useMemo)(() => patternCategoryTypes.map(patternCategoryType => patternCategoryType.name), [patternCategoryTypes]);
1080 const baseClassName = 'patternswp__sidebar';
1081 return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
1082 className: baseClassName
1083 }, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
1084 className: `${baseClassName}__search`
1085 }, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_2__.SearchControl, {
1086 value: searchValue,
1087 onChange: setSearchValue,
1088 label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)('Search patterns', 'patternswp')
1089 })), patternCategoryTypes.map(categoryType => {
1090 const categoriesOfType = patternCategories.filter(category => {
1091 // If the selected category is uncategorized, return all
1092 // pattern categories without assigned category types.
1093 if (categoryType.name === 'uncategorized') {
1094 return !category?.categoryTypes || category.categoryTypes.every(type => !registeredCategoryTypes.includes(type));
1095 }
1096 return category.categoryTypes?.includes(categoryType.name);
1097 });
1098
1099 // If there are no categories in the current type, bail.
1100 if (!categoriesOfType.length) {
1101 return null;
1102 }
1103 return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
1104 key: categoryType,
1105 className: `${baseClassName}__category-type`
1106 }, categoryType?.hideLabelFromVision ? (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_2__.VisuallyHidden, {
1107 as: "h2"
1108 }, categoryType.label) : (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("h2", {
1109 className: `${baseClassName}__category-type__title`
1110 }, categoryType.label), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
1111 className: `${baseClassName}__category-type__categories`
1112 }, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_2__.MenuGroup, {
1113 className: `${baseClassName}__categories-list`
1114 }, categoriesOfType.map(category => {
1115 return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_2__.MenuItem, {
1116 key: category.name,
1117 label: category.label,
1118 className: `${baseClassName}__categories-list__item`,
1119 isPressed: !searchValue && category.name === selectedCategory,
1120 onClick: () => onClickCategory(category.name)
1121 }, category.label);
1122 }))));
1123 }));
1124 }
1125
1126 /***/ }),
1127
1128 /***/ "react":
1129 /*!************************!*\
1130 !*** external "React" ***!
1131 \************************/
1132 /***/ ((module) => {
1133
1134 "use strict";
1135 module.exports = window["React"];
1136
1137 /***/ }),
1138
1139 /***/ "lodash":
1140 /*!*************************!*\
1141 !*** external "lodash" ***!
1142 \*************************/
1143 /***/ ((module) => {
1144
1145 "use strict";
1146 module.exports = window["lodash"];
1147
1148 /***/ }),
1149
1150 /***/ "@wordpress/a11y":
1151 /*!******************************!*\
1152 !*** external ["wp","a11y"] ***!
1153 \******************************/
1154 /***/ ((module) => {
1155
1156 "use strict";
1157 module.exports = window["wp"]["a11y"];
1158
1159 /***/ }),
1160
1161 /***/ "@wordpress/block-editor":
1162 /*!*************************************!*\
1163 !*** external ["wp","blockEditor"] ***!
1164 \*************************************/
1165 /***/ ((module) => {
1166
1167 "use strict";
1168 module.exports = window["wp"]["blockEditor"];
1169
1170 /***/ }),
1171
1172 /***/ "@wordpress/blocks":
1173 /*!********************************!*\
1174 !*** external ["wp","blocks"] ***!
1175 \********************************/
1176 /***/ ((module) => {
1177
1178 "use strict";
1179 module.exports = window["wp"]["blocks"];
1180
1181 /***/ }),
1182
1183 /***/ "@wordpress/components":
1184 /*!************************************!*\
1185 !*** external ["wp","components"] ***!
1186 \************************************/
1187 /***/ ((module) => {
1188
1189 "use strict";
1190 module.exports = window["wp"]["components"];
1191
1192 /***/ }),
1193
1194 /***/ "@wordpress/compose":
1195 /*!*********************************!*\
1196 !*** external ["wp","compose"] ***!
1197 \*********************************/
1198 /***/ ((module) => {
1199
1200 "use strict";
1201 module.exports = window["wp"]["compose"];
1202
1203 /***/ }),
1204
1205 /***/ "@wordpress/data":
1206 /*!******************************!*\
1207 !*** external ["wp","data"] ***!
1208 \******************************/
1209 /***/ ((module) => {
1210
1211 "use strict";
1212 module.exports = window["wp"]["data"];
1213
1214 /***/ }),
1215
1216 /***/ "@wordpress/element":
1217 /*!*********************************!*\
1218 !*** external ["wp","element"] ***!
1219 \*********************************/
1220 /***/ ((module) => {
1221
1222 "use strict";
1223 module.exports = window["wp"]["element"];
1224
1225 /***/ }),
1226
1227 /***/ "@wordpress/i18n":
1228 /*!******************************!*\
1229 !*** external ["wp","i18n"] ***!
1230 \******************************/
1231 /***/ ((module) => {
1232
1233 "use strict";
1234 module.exports = window["wp"]["i18n"];
1235
1236 /***/ }),
1237
1238 /***/ "@wordpress/notices":
1239 /*!*********************************!*\
1240 !*** external ["wp","notices"] ***!
1241 \*********************************/
1242 /***/ ((module) => {
1243
1244 "use strict";
1245 module.exports = window["wp"]["notices"];
1246
1247 /***/ }),
1248
1249 /***/ "@wordpress/primitives":
1250 /*!************************************!*\
1251 !*** external ["wp","primitives"] ***!
1252 \************************************/
1253 /***/ ((module) => {
1254
1255 "use strict";
1256 module.exports = window["wp"]["primitives"];
1257
1258 /***/ }),
1259
1260 /***/ "./node_modules/classnames/index.js":
1261 /*!******************************************!*\
1262 !*** ./node_modules/classnames/index.js ***!
1263 \******************************************/
1264 /***/ ((module, exports) => {
1265
1266 var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/*!
1267 Copyright (c) 2018 Jed Watson.
1268 Licensed under the MIT License (MIT), see
1269 http://jedwatson.github.io/classnames
1270 */
1271 /* global define */
1272
1273 (function () {
1274 'use strict';
1275
1276 var hasOwn = {}.hasOwnProperty;
1277
1278 function classNames () {
1279 var classes = '';
1280
1281 for (var i = 0; i < arguments.length; i++) {
1282 var arg = arguments[i];
1283 if (arg) {
1284 classes = appendClass(classes, parseValue(arg));
1285 }
1286 }
1287
1288 return classes;
1289 }
1290
1291 function parseValue (arg) {
1292 if (typeof arg === 'string' || typeof arg === 'number') {
1293 return arg;
1294 }
1295
1296 if (typeof arg !== 'object') {
1297 return '';
1298 }
1299
1300 if (Array.isArray(arg)) {
1301 return classNames.apply(null, arg);
1302 }
1303
1304 if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes('[native code]')) {
1305 return arg.toString();
1306 }
1307
1308 var classes = '';
1309
1310 for (var key in arg) {
1311 if (hasOwn.call(arg, key) && arg[key]) {
1312 classes = appendClass(classes, key);
1313 }
1314 }
1315
1316 return classes;
1317 }
1318
1319 function appendClass (value, newClass) {
1320 if (!newClass) {
1321 return value;
1322 }
1323
1324 if (value) {
1325 return value + ' ' + newClass;
1326 }
1327
1328 return value + newClass;
1329 }
1330
1331 if ( true && module.exports) {
1332 classNames.default = classNames;
1333 module.exports = classNames;
1334 } else if (true) {
1335 // register as 'classnames', consistent with npm package name
1336 !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = (function () {
1337 return classNames;
1338 }).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),
1339 __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
1340 } else {}
1341 }());
1342
1343
1344 /***/ })
1345
1346 /******/ });
1347 /************************************************************************/
1348 /******/ // The module cache
1349 /******/ var __webpack_module_cache__ = {};
1350 /******/
1351 /******/ // The require function
1352 /******/ function __webpack_require__(moduleId) {
1353 /******/ // Check if module is in cache
1354 /******/ var cachedModule = __webpack_module_cache__[moduleId];
1355 /******/ if (cachedModule !== undefined) {
1356 /******/ return cachedModule.exports;
1357 /******/ }
1358 /******/ // Create a new module (and put it into the cache)
1359 /******/ var module = __webpack_module_cache__[moduleId] = {
1360 /******/ // no module.id needed
1361 /******/ // no module.loaded needed
1362 /******/ exports: {}
1363 /******/ };
1364 /******/
1365 /******/ // Execute the module function
1366 /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
1367 /******/
1368 /******/ // Return the exports of the module
1369 /******/ return module.exports;
1370 /******/ }
1371 /******/
1372 /************************************************************************/
1373 /******/ /* webpack/runtime/compat get default export */
1374 /******/ (() => {
1375 /******/ // getDefaultExport function for compatibility with non-harmony modules
1376 /******/ __webpack_require__.n = (module) => {
1377 /******/ var getter = module && module.__esModule ?
1378 /******/ () => (module['default']) :
1379 /******/ () => (module);
1380 /******/ __webpack_require__.d(getter, { a: getter });
1381 /******/ return getter;
1382 /******/ };
1383 /******/ })();
1384 /******/
1385 /******/ /* webpack/runtime/define property getters */
1386 /******/ (() => {
1387 /******/ // define getter functions for harmony exports
1388 /******/ __webpack_require__.d = (exports, definition) => {
1389 /******/ for(var key in definition) {
1390 /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
1391 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
1392 /******/ }
1393 /******/ }
1394 /******/ };
1395 /******/ })();
1396 /******/
1397 /******/ /* webpack/runtime/hasOwnProperty shorthand */
1398 /******/ (() => {
1399 /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
1400 /******/ })();
1401 /******/
1402 /******/ /* webpack/runtime/make namespace object */
1403 /******/ (() => {
1404 /******/ // define __esModule on exports
1405 /******/ __webpack_require__.r = (exports) => {
1406 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
1407 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1408 /******/ }
1409 /******/ Object.defineProperty(exports, '__esModule', { value: true });
1410 /******/ };
1411 /******/ })();
1412 /******/
1413 /************************************************************************/
1414 var __webpack_exports__ = {};
1415 // This entry need to be wrapped in an IIFE because it need to be in strict mode.
1416 (() => {
1417 "use strict";
1418 /*!**********************!*\
1419 !*** ./src/index.js ***!
1420 \**********************/
1421 __webpack_require__.r(__webpack_exports__);
1422 /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
1423 /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
1424 /* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! lodash */ "lodash");
1425 /* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_1__);
1426 /* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n");
1427 /* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__);
1428 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element");
1429 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_3__);
1430 /* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data");
1431 /* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_4__);
1432 /* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @wordpress/components */ "@wordpress/components");
1433 /* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_wordpress_components__WEBPACK_IMPORTED_MODULE_5__);
1434 /* harmony import */ var _pattern_explorer__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./pattern-explorer */ "./src/pattern-explorer.js");
1435 /* harmony import */ var _core_hooks_use_patterns_state__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./core-hooks/use-patterns-state */ "./src/core-hooks/use-patterns-state.js");
1436
1437 /**
1438 * External dependencies.
1439 */
1440
1441
1442 /**
1443 * WordPress dependencies.
1444 */
1445
1446
1447
1448
1449
1450 /**
1451 * Internal dependencies
1452 */
1453
1454
1455
1456 /**
1457 * Render the header toolbar button and the accompanying pattern explorer modal.
1458 *
1459 * @since 0.1.0
1460 * @return {string} Return the rendered JSX for the Pattern Explorer Button
1461 */
1462 function HeaderToolbarButton() {
1463 const [isModalOpen, setIsModalOpen] = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_3__.useState)(false);
1464 const [allPatterns, allCategories, allCategoryTypes] = (0,_core_hooks_use_patterns_state__WEBPACK_IMPORTED_MODULE_7__["default"])();
1465 const fetchedCategoryTypes = allCategoryTypes === 'fetching' ? [] : allCategoryTypes;
1466
1467 // Check if a pattern category has an assigned pattern category type.
1468 const hasRegisteredCategoryType = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_3__.useCallback)(category => {
1469 if (!category.categoryTypes || !category.categoryTypes.length) {
1470 return false;
1471 }
1472 return category.categoryTypes.some(type => fetchedCategoryTypes.some(categoryType => categoryType.name === type));
1473 }, [fetchedCategoryTypes]);
1474 const onCloseModal = () => {
1475 setIsModalOpen(false);
1476 };
1477
1478 // Remove any categories without patterns and not in selected categories.
1479 const populatedCategories = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_3__.useMemo)(() => {
1480 const filteredCategories = allCategories.filter(category => category.name.startsWith('patternswp-'));
1481
1482 // Create labels dynamically for categories
1483 const categorizedLabels = filteredCategories.map(category => ({
1484 ...category,
1485 label: category.name.replace('patternswp-', '').replace(/-/g, ' ').replace(/\b\w/g, char => char.toUpperCase())
1486 }));
1487
1488 // Add the "All" option
1489 const allOption = {
1490 name: 'all',
1491 label: 'All'
1492 };
1493 return [allOption, ...categorizedLabels];
1494 }, [allCategories]);
1495
1496 // Remove any pattern category type without populated pattern categories.
1497 const populatedCategoryTypes = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_3__.useMemo)(() => {
1498 const categoryTypes = fetchedCategoryTypes.filter(type => populatedCategories.some(category => category.categoryTypes?.includes(type.name)));
1499
1500 // If there are categories without types, create the Uncategorized type.
1501 if (populatedCategories.some(category => !hasRegisteredCategoryType(category)) && !categoryTypes.find(type => type.name === 'uncategorized')) {
1502 categoryTypes.unshift({
1503 name: 'uncategorized',
1504 label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__.__)('Uncategorized', 'patternswp'),
1505 hideLabelFromVision: true
1506 });
1507 }
1508 return categoryTypes;
1509 }, [populatedCategories, fetchedCategoryTypes]);
1510
1511 // Could expand on this in the future, i.e. allow for a configurable
1512 // initial category. For now the initial category is the first category in
1513 // the first category type.
1514 const initialCategory = populatedCategories[0];
1515
1516 // If there are no patterns, do not display the pattern explorer button.
1517 if ((0,lodash__WEBPACK_IMPORTED_MODULE_1__.isEmpty)(allPatterns)) {
1518 return null;
1519 }
1520 (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_3__.useEffect)(() => {
1521 const observerCallback = mutationsList => {
1522 for (const mutation of mutationsList) {
1523 if (mutation.type === 'childList' && mutation.addedNodes.length) {
1524 document.querySelectorAll('.components-dropdown.block-editor-inserter').forEach(dropdown => {
1525 addButton(dropdown);
1526 });
1527 }
1528 }
1529 };
1530 const observer = new MutationObserver(observerCallback);
1531 observer.observe(document.body, {
1532 subtree: true,
1533 childList: true
1534 });
1535 const addButton = $dropdown => {
1536 if (!$dropdown.querySelector('.patternswp-appender-button')) {
1537 const $appenderButton = document.createElement('button');
1538 $appenderButton.type = 'button';
1539 $appenderButton.setAttribute('aria-haspopup', 'true');
1540 $appenderButton.className = 'components-button block-editor-inserter__toggle has-icon patternswp-appender-button';
1541 $appenderButton.innerHTML = `<svg width="20" height="20" viewBox="0 0 25 37" fill="#ffffff" xmlns="http://www.w3.org/2000/svg">
1542 <mask id="mask0_671_1966" style="mask-type:luminance" maskUnits="userSpaceOnUse" x="0" y="18" width="9" height="19" fill="#ffffff" ><path d="M0 18.3303H8.23816V36.3607H0V18.3303Z" fill="#ffffff"/></mask>
1543 <g mask="url(#mask0_671_1966)"><path fill-rule="evenodd" clip-rule="evenodd" d="M0.625738 32.0853L8.04102 36.3602V18.5413L-0.000976562 23.1771V31.7244L0.625738 32.0853Z" fill="#ffffff"/></g>
1544 <mask id="mask1_671_1966" style="mask-type:luminance" maskUnits="userSpaceOnUse" x="10" y="9" width="15" height="18"><path d="M10.1934 9.198H24.1297V26.5898H10.1934V9.198Z" fill="#ffffff"/></mask>
1545 <g mask="url(#mask1_671_1966)"><path fill-rule="evenodd" clip-rule="evenodd" d="M10.2178 17.2857V26.5548L16.0824 23.1758L24.1278 18.54V9.26831L16.0824 13.9041L10.2178 17.2857Z" fill="#ffffff"/></g>
1546 <mask id="mask2_671_1966" style="mask-type:luminance" maskUnits="userSpaceOnUse" x="16" y="4" width="9" height="10"><path d="M16.0645 4.63403H24.1311V13.9821H16.0645V4.63403Z" fill="#ffffff"/></mask>
1547 <g mask="url(#mask2_671_1966)"><path fill-rule="evenodd" clip-rule="evenodd" d="M16.083 13.9058L24.1284 9.26999L16.083 4.63672V13.9058Z" fill="#ffffff"/></g>
1548 <mask id="mask3_671_1966" style="mask-type:luminance" maskUnits="userSpaceOnUse" x="0" y="0" width="17" height="14">
1549 <path d="M0 0H16.2819V13.9813H0V0Z" fill="#ffffff"/></mask><g mask="url(#mask3_671_1966)"><path fill-rule="evenodd" clip-rule="evenodd" d="M8.04102 9.2691L16.083 4.63582L8.04102 0L-0.000976562 4.63582V13.9049L8.04102 9.2691Z" fill="#ffffff"/></g>
1550 </svg>`;
1551 $appenderButton.style.marginLeft = '8px';
1552 $dropdown.appendChild($appenderButton);
1553 $dropdown.style.display = 'flex';
1554 $dropdown.style.gap = '5px';
1555 $appenderButton.addEventListener('click', () => {
1556 setIsModalOpen(true);
1557 });
1558 }
1559 };
1560 const checkButtonPresence = () => {
1561 const dropdowns = document.querySelectorAll('iframe[name="editor-canvas"]').forEach(iframe => {
1562 const $dropdown = iframe.contentDocument.querySelector('.components-dropdown.block-editor-inserter');
1563 if ($dropdown) {
1564 addButton($dropdown);
1565 }
1566 });
1567 setTimeout(checkButtonPresence, 200);
1568 };
1569 checkButtonPresence();
1570 return () => {
1571 observer.disconnect();
1572 };
1573 }, []);
1574 return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_5__.Button, {
1575 className: "components-button is-button is-primary patternswp-button" // Add custom classes for styling
1576 ,
1577 onClick: () => setIsModalOpen(true)
1578 }, "PatternsWP Library"), isModalOpen && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_5__.Modal, {
1579 title: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__.__)('PatternsWP', 'patternswp'),
1580 closeLabel: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__.__)('Close', 'patternswp'),
1581 onRequestClose: onCloseModal,
1582 className: "patternswp__modal",
1583 isFullScreen: true
1584 }, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_pattern_explorer__WEBPACK_IMPORTED_MODULE_6__["default"], {
1585 allPatterns: allPatterns,
1586 initialCategory: initialCategory,
1587 patternCategories: populatedCategories,
1588 patternCategoryTypes: populatedCategoryTypes,
1589 categoryTypes: true,
1590 onRequestClose: onCloseModal
1591 })));
1592 }
1593
1594 /**
1595 * Add the header toolbar button to the block editor.
1596 */
1597 (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_4__.subscribe)(() => {
1598 const inserter = document.querySelector('#patternswp');
1599
1600 // If the inserter already exists, bail.
1601 if (inserter) {
1602 return;
1603 }
1604 wp.domReady(() => {
1605 const toolbar = document.querySelector('.edit-post-header-toolbar');
1606
1607 // If no toolbar can be found at all, bail.
1608 if (!toolbar) {
1609 return;
1610 }
1611 const buttonContainer = document.createElement('div');
1612 buttonContainer.id = 'patternswp';
1613 toolbar.appendChild(buttonContainer);
1614 (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_3__.render)((0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(HeaderToolbarButton, null), document.getElementById('patternswp'));
1615 });
1616 });
1617
1618 /**
1619 * (Experimental) Add support for the pattern category type setting.
1620 *
1621 * @param {Array} settings All editor settings
1622 * @since 0.2.0
1623 */
1624
1625 /**
1626 * Add our custom entities for retrieving external data in the Block Editor.
1627 *
1628 * @since 0.2.0
1629 */
1630 (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_4__.dispatch)('core').addEntities([{
1631 label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__.__)('Pattern Category Types', 'patternswp'),
1632 kind: 'patternswp/v1',
1633 name: 'patternCategoryTypes',
1634 baseURL: '/patternswp/v1/pattern-category-types'
1635 }]);
1636 })();
1637
1638 /******/ })()
1639 ;
1640 //# sourceMappingURL=patternswp-editor.js.map