PluginProbe
Gutenberg / 19.6.4
Gutenberg v19.6.4
24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 All 403 releases
gutenberg / build / customize-widgets / index.js

index.js in Gutenberg 19.6.4, at build/customize-widgets/index.js

2,739 lines 95.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /******/ (() => { // webpackBootstrap
2 /******/ "use strict";
3 /******/ var __webpack_modules__ = ({
4
5 /***/ 7734:
6 /***/ ((module) => {
7
8
9
10 // do not edit .js files directly - edit src/index.jst
11
12
13 var envHasBigInt64Array = typeof BigInt64Array !== 'undefined';
14
15
16 module.exports = function equal(a, b) {
17 if (a === b) return true;
18
19 if (a && b && typeof a == 'object' && typeof b == 'object') {
20 if (a.constructor !== b.constructor) return false;
21
22 var length, i, keys;
23 if (Array.isArray(a)) {
24 length = a.length;
25 if (length != b.length) return false;
26 for (i = length; i-- !== 0;)
27 if (!equal(a[i], b[i])) return false;
28 return true;
29 }
30
31
32 if ((a instanceof Map) && (b instanceof Map)) {
33 if (a.size !== b.size) return false;
34 for (i of a.entries())
35 if (!b.has(i[0])) return false;
36 for (i of a.entries())
37 if (!equal(i[1], b.get(i[0]))) return false;
38 return true;
39 }
40
41 if ((a instanceof Set) && (b instanceof Set)) {
42 if (a.size !== b.size) return false;
43 for (i of a.entries())
44 if (!b.has(i[0])) return false;
45 return true;
46 }
47
48 if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) {
49 length = a.length;
50 if (length != b.length) return false;
51 for (i = length; i-- !== 0;)
52 if (a[i] !== b[i]) return false;
53 return true;
54 }
55
56
57 if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
58 if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
59 if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
60
61 keys = Object.keys(a);
62 length = keys.length;
63 if (length !== Object.keys(b).length) return false;
64
65 for (i = length; i-- !== 0;)
66 if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
67
68 for (i = length; i-- !== 0;) {
69 var key = keys[i];
70
71 if (!equal(a[key], b[key])) return false;
72 }
73
74 return true;
75 }
76
77 // true if both NaN, false otherwise
78 return a!==a && b!==b;
79 };
80
81
82 /***/ })
83
84 /******/ });
85 /************************************************************************/
86 /******/ // The module cache
87 /******/ var __webpack_module_cache__ = {};
88 /******/
89 /******/ // The require function
90 /******/ function __webpack_require__(moduleId) {
91 /******/ // Check if module is in cache
92 /******/ var cachedModule = __webpack_module_cache__[moduleId];
93 /******/ if (cachedModule !== undefined) {
94 /******/ return cachedModule.exports;
95 /******/ }
96 /******/ // Create a new module (and put it into the cache)
97 /******/ var module = __webpack_module_cache__[moduleId] = {
98 /******/ // no module.id needed
99 /******/ // no module.loaded needed
100 /******/ exports: {}
101 /******/ };
102 /******/
103 /******/ // Execute the module function
104 /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
105 /******/
106 /******/ // Return the exports of the module
107 /******/ return module.exports;
108 /******/ }
109 /******/
110 /************************************************************************/
111 /******/ /* webpack/runtime/compat get default export */
112 /******/ (() => {
113 /******/ // getDefaultExport function for compatibility with non-harmony modules
114 /******/ __webpack_require__.n = (module) => {
115 /******/ var getter = module && module.__esModule ?
116 /******/ () => (module['default']) :
117 /******/ () => (module);
118 /******/ __webpack_require__.d(getter, { a: getter });
119 /******/ return getter;
120 /******/ };
121 /******/ })();
122 /******/
123 /******/ /* webpack/runtime/define property getters */
124 /******/ (() => {
125 /******/ // define getter functions for harmony exports
126 /******/ __webpack_require__.d = (exports, definition) => {
127 /******/ for(var key in definition) {
128 /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
129 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
130 /******/ }
131 /******/ }
132 /******/ };
133 /******/ })();
134 /******/
135 /******/ /* webpack/runtime/hasOwnProperty shorthand */
136 /******/ (() => {
137 /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
138 /******/ })();
139 /******/
140 /******/ /* webpack/runtime/make namespace object */
141 /******/ (() => {
142 /******/ // define __esModule on exports
143 /******/ __webpack_require__.r = (exports) => {
144 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
145 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
146 /******/ }
147 /******/ Object.defineProperty(exports, '__esModule', { value: true });
148 /******/ };
149 /******/ })();
150 /******/
151 /************************************************************************/
152 var __webpack_exports__ = {};
153 // ESM COMPAT FLAG
154 __webpack_require__.r(__webpack_exports__);
155
156 // EXPORTS
157 __webpack_require__.d(__webpack_exports__, {
158 initialize: () => (/* binding */ initialize),
159 store: () => (/* reexport */ store)
160 });
161
162 // NAMESPACE OBJECT: ./packages/customize-widgets/build-module/store/selectors.js
163 var selectors_namespaceObject = {};
164 __webpack_require__.r(selectors_namespaceObject);
165 __webpack_require__.d(selectors_namespaceObject, {
166 __experimentalGetInsertionPoint: () => (__experimentalGetInsertionPoint),
167 isInserterOpened: () => (isInserterOpened)
168 });
169
170 // NAMESPACE OBJECT: ./packages/customize-widgets/build-module/store/actions.js
171 var actions_namespaceObject = {};
172 __webpack_require__.r(actions_namespaceObject);
173 __webpack_require__.d(actions_namespaceObject, {
174 setIsInserterOpened: () => (setIsInserterOpened)
175 });
176
177 ;// external ["wp","element"]
178 const external_wp_element_namespaceObject = window["wp"]["element"];
179 ;// external ["wp","blockLibrary"]
180 const external_wp_blockLibrary_namespaceObject = window["wp"]["blockLibrary"];
181 ;// external ["wp","widgets"]
182 const external_wp_widgets_namespaceObject = window["wp"]["widgets"];
183 ;// external ["wp","blocks"]
184 const external_wp_blocks_namespaceObject = window["wp"]["blocks"];
185 ;// external ["wp","data"]
186 const external_wp_data_namespaceObject = window["wp"]["data"];
187 ;// external ["wp","editor"]
188 const external_wp_editor_namespaceObject = window["wp"]["editor"];
189 ;// external ["wp","preferences"]
190 const external_wp_preferences_namespaceObject = window["wp"]["preferences"];
191 ;// external ["wp","components"]
192 const external_wp_components_namespaceObject = window["wp"]["components"];
193 ;// external ["wp","i18n"]
194 const external_wp_i18n_namespaceObject = window["wp"]["i18n"];
195 ;// external ["wp","blockEditor"]
196 const external_wp_blockEditor_namespaceObject = window["wp"]["blockEditor"];
197 ;// external ["wp","compose"]
198 const external_wp_compose_namespaceObject = window["wp"]["compose"];
199 ;// external ["wp","hooks"]
200 const external_wp_hooks_namespaceObject = window["wp"]["hooks"];
201 ;// external "ReactJSXRuntime"
202 const external_ReactJSXRuntime_namespaceObject = window["ReactJSXRuntime"];
203 ;// ./packages/customize-widgets/build-module/components/error-boundary/index.js
204 /**
205 * WordPress dependencies
206 */
207
208
209
210
211
212
213
214 function CopyButton({
215 text,
216 children
217 }) {
218 const ref = (0,external_wp_compose_namespaceObject.useCopyToClipboard)(text);
219 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Button, {
220 size: "compact",
221 variant: "secondary",
222 ref: ref,
223 children: children
224 });
225 }
226 class ErrorBoundary extends external_wp_element_namespaceObject.Component {
227 constructor() {
228 super(...arguments);
229 this.state = {
230 error: null
231 };
232 }
233 componentDidCatch(error) {
234 this.setState({
235 error
236 });
237 (0,external_wp_hooks_namespaceObject.doAction)('editor.ErrorBoundary.errorLogged', error);
238 }
239 render() {
240 const {
241 error
242 } = this.state;
243 if (!error) {
244 return this.props.children;
245 }
246 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.Warning, {
247 className: "customize-widgets-error-boundary",
248 actions: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(CopyButton, {
249 text: error.stack,
250 children: (0,external_wp_i18n_namespaceObject.__)('Copy Error')
251 }, "copy-error")],
252 children: (0,external_wp_i18n_namespaceObject.__)('The editor has encountered an unexpected error.')
253 });
254 }
255 }
256
257 ;// external ["wp","coreData"]
258 const external_wp_coreData_namespaceObject = window["wp"]["coreData"];
259 ;// external ["wp","mediaUtils"]
260 const external_wp_mediaUtils_namespaceObject = window["wp"]["mediaUtils"];
261 ;// ./packages/customize-widgets/build-module/components/block-inspector-button/index.js
262 /**
263 * WordPress dependencies
264 */
265
266
267
268
269
270
271 function BlockInspectorButton({
272 inspector,
273 closeMenu,
274 ...props
275 }) {
276 const selectedBlockClientId = (0,external_wp_data_namespaceObject.useSelect)(select => select(external_wp_blockEditor_namespaceObject.store).getSelectedBlockClientId(), []);
277 const selectedBlock = (0,external_wp_element_namespaceObject.useMemo)(() => document.getElementById(`block-${selectedBlockClientId}`), [selectedBlockClientId]);
278 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.MenuItem, {
279 onClick: () => {
280 // Open the inspector.
281 inspector.open({
282 returnFocusWhenClose: selectedBlock
283 });
284 // Then close the dropdown menu.
285 closeMenu();
286 },
287 ...props,
288 children: (0,external_wp_i18n_namespaceObject.__)('Show more settings')
289 });
290 }
291 /* harmony default export */ const block_inspector_button = (BlockInspectorButton);
292
293 ;// ./node_modules/clsx/dist/clsx.mjs
294 function r(e){var t,f,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=" "),n+=f)}else for(f in e)e[f]&&(n&&(n+=" "),n+=f);return n}function clsx(){for(var e,t,f=0,n="",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r(e))&&(n&&(n+=" "),n+=t);return n}/* harmony default export */ const dist_clsx = (clsx);
295 ;// external ["wp","keycodes"]
296 const external_wp_keycodes_namespaceObject = window["wp"]["keycodes"];
297 ;// external ["wp","primitives"]
298 const external_wp_primitives_namespaceObject = window["wp"]["primitives"];
299 ;// ./packages/icons/build-module/library/undo.js
300 /**
301 * WordPress dependencies
302 */
303
304
305 const undo = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
306 xmlns: "http://www.w3.org/2000/svg",
307 viewBox: "0 0 24 24",
308 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
309 d: "M18.3 11.7c-.6-.6-1.4-.9-2.3-.9H6.7l2.9-3.3-1.1-1-4.5 5L8.5 16l1-1-2.7-2.7H16c.5 0 .9.2 1.3.5 1 1 1 3.4 1 4.5v.3h1.5v-.2c0-1.5 0-4.3-1.5-5.7z"
310 })
311 });
312 /* harmony default export */ const library_undo = (undo);
313
314 ;// ./packages/icons/build-module/library/redo.js
315 /**
316 * WordPress dependencies
317 */
318
319
320 const redo = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
321 xmlns: "http://www.w3.org/2000/svg",
322 viewBox: "0 0 24 24",
323 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
324 d: "M15.6 6.5l-1.1 1 2.9 3.3H8c-.9 0-1.7.3-2.3.9-1.4 1.5-1.4 4.2-1.4 5.6v.2h1.5v-.3c0-1.1 0-3.5 1-4.5.3-.3.7-.5 1.3-.5h9.2L14.5 15l1.1 1.1 4.6-4.6-4.6-5z"
325 })
326 });
327 /* harmony default export */ const library_redo = (redo);
328
329 ;// ./packages/icons/build-module/library/plus.js
330 /**
331 * WordPress dependencies
332 */
333
334
335 const plus = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
336 xmlns: "http://www.w3.org/2000/svg",
337 viewBox: "0 0 24 24",
338 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
339 d: "M11 12.5V17.5H12.5V12.5H17.5V11H12.5V6H11V11H6V12.5H11Z"
340 })
341 });
342 /* harmony default export */ const library_plus = (plus);
343
344 ;// ./packages/icons/build-module/library/close-small.js
345 /**
346 * WordPress dependencies
347 */
348
349
350 const closeSmall = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
351 xmlns: "http://www.w3.org/2000/svg",
352 viewBox: "0 0 24 24",
353 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
354 d: "M12 13.06l3.712 3.713 1.061-1.06L13.061 12l3.712-3.712-1.06-1.06L12 10.938 8.288 7.227l-1.061 1.06L10.939 12l-3.712 3.712 1.06 1.061L12 13.061z"
355 })
356 });
357 /* harmony default export */ const close_small = (closeSmall);
358
359 ;// ./packages/customize-widgets/build-module/store/reducer.js
360 /**
361 * WordPress dependencies
362 */
363
364
365 /**
366 * Reducer tracking whether the inserter is open.
367 *
368 * @param {boolean|Object} state
369 * @param {Object} action
370 */
371 function blockInserterPanel(state = false, action) {
372 switch (action.type) {
373 case 'SET_IS_INSERTER_OPENED':
374 return action.value;
375 }
376 return state;
377 }
378 /* harmony default export */ const reducer = ((0,external_wp_data_namespaceObject.combineReducers)({
379 blockInserterPanel
380 }));
381
382 ;// ./packages/customize-widgets/build-module/store/selectors.js
383 const EMPTY_INSERTION_POINT = {
384 rootClientId: undefined,
385 insertionIndex: undefined
386 };
387
388 /**
389 * Returns true if the inserter is opened.
390 *
391 * @param {Object} state Global application state.
392 *
393 * @example
394 * ```js
395 * import { store as customizeWidgetsStore } from '@wordpress/customize-widgets';
396 * import { __ } from '@wordpress/i18n';
397 * import { useSelect } from '@wordpress/data';
398 *
399 * const ExampleComponent = () => {
400 * const { isInserterOpened } = useSelect(
401 * ( select ) => select( customizeWidgetsStore ),
402 * []
403 * );
404 *
405 * return isInserterOpened()
406 * ? __( 'Inserter is open' )
407 * : __( 'Inserter is closed.' );
408 * };
409 * ```
410 *
411 * @return {boolean} Whether the inserter is opened.
412 */
413 function isInserterOpened(state) {
414 return !!state.blockInserterPanel;
415 }
416
417 /**
418 * Get the insertion point for the inserter.
419 *
420 * @param {Object} state Global application state.
421 *
422 * @return {Object} The root client ID and index to insert at.
423 */
424 function __experimentalGetInsertionPoint(state) {
425 if (typeof state.blockInserterPanel === 'boolean') {
426 return EMPTY_INSERTION_POINT;
427 }
428 return state.blockInserterPanel;
429 }
430
431 ;// ./packages/customize-widgets/build-module/store/actions.js
432 /**
433 * Returns an action object used to open/close the inserter.
434 *
435 * @param {boolean|Object} value Whether the inserter should be
436 * opened (true) or closed (false).
437 * To specify an insertion point,
438 * use an object.
439 * @param {string} value.rootClientId The root client ID to insert at.
440 * @param {number} value.insertionIndex The index to insert at.
441 *
442 * @example
443 * ```js
444 * import { useState } from 'react';
445 * import { store as customizeWidgetsStore } from '@wordpress/customize-widgets';
446 * import { __ } from '@wordpress/i18n';
447 * import { useDispatch } from '@wordpress/data';
448 * import { Button } from '@wordpress/components';
449 *
450 * const ExampleComponent = () => {
451 * const { setIsInserterOpened } = useDispatch( customizeWidgetsStore );
452 * const [ isOpen, setIsOpen ] = useState( false );
453 *
454 * return (
455 * <Button
456 * onClick={ () => {
457 * setIsInserterOpened( ! isOpen );
458 * setIsOpen( ! isOpen );
459 * } }
460 * >
461 * { __( 'Open/close inserter' ) }
462 * </Button>
463 * );
464 * };
465 * ```
466 *
467 * @return {Object} Action object.
468 */
469 function setIsInserterOpened(value) {
470 return {
471 type: 'SET_IS_INSERTER_OPENED',
472 value
473 };
474 }
475
476 ;// ./packages/customize-widgets/build-module/store/constants.js
477 /**
478 * Module Constants
479 */
480 const STORE_NAME = 'core/customize-widgets';
481
482 ;// ./packages/customize-widgets/build-module/store/index.js
483 /**
484 * WordPress dependencies
485 */
486
487
488 /**
489 * Internal dependencies
490 */
491
492
493
494
495
496 /**
497 * Block editor data store configuration.
498 *
499 * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#registering-a-store
500 *
501 * @type {Object}
502 */
503 const storeConfig = {
504 reducer: reducer,
505 selectors: selectors_namespaceObject,
506 actions: actions_namespaceObject
507 };
508
509 /**
510 * Store definition for the edit widgets namespace.
511 *
512 * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
513 *
514 * @type {Object}
515 */
516 const store = (0,external_wp_data_namespaceObject.createReduxStore)(STORE_NAME, storeConfig);
517 (0,external_wp_data_namespaceObject.register)(store);
518
519 ;// ./packages/customize-widgets/build-module/components/inserter/index.js
520 /**
521 * WordPress dependencies
522 */
523
524
525
526
527
528
529
530 /**
531 * Internal dependencies
532 */
533
534
535 function Inserter({
536 setIsOpened
537 }) {
538 const inserterTitleId = (0,external_wp_compose_namespaceObject.useInstanceId)(Inserter, 'customize-widget-layout__inserter-panel-title');
539 const insertionPoint = (0,external_wp_data_namespaceObject.useSelect)(select => select(store).__experimentalGetInsertionPoint(), []);
540 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)("div", {
541 className: "customize-widgets-layout__inserter-panel",
542 "aria-labelledby": inserterTitleId,
543 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)("div", {
544 className: "customize-widgets-layout__inserter-panel-header",
545 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("h2", {
546 id: inserterTitleId,
547 className: "customize-widgets-layout__inserter-panel-header-title",
548 children: (0,external_wp_i18n_namespaceObject.__)('Add a block')
549 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Button, {
550 size: "small",
551 icon: close_small,
552 onClick: () => setIsOpened(false),
553 "aria-label": (0,external_wp_i18n_namespaceObject.__)('Close inserter')
554 })]
555 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", {
556 className: "customize-widgets-layout__inserter-panel-content",
557 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.__experimentalLibrary, {
558 rootClientId: insertionPoint.rootClientId,
559 __experimentalInsertionIndex: insertionPoint.insertionIndex,
560 showInserterHelpPanel: true,
561 onSelect: () => setIsOpened(false)
562 })
563 })]
564 });
565 }
566 /* harmony default export */ const components_inserter = (Inserter);
567
568 ;// ./packages/icons/build-module/library/more-vertical.js
569 /**
570 * WordPress dependencies
571 */
572
573
574 const moreVertical = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
575 xmlns: "http://www.w3.org/2000/svg",
576 viewBox: "0 0 24 24",
577 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
578 d: "M13 19h-2v-2h2v2zm0-6h-2v-2h2v2zm0-6h-2V5h2v2z"
579 })
580 });
581 /* harmony default export */ const more_vertical = (moreVertical);
582
583 ;// ./packages/icons/build-module/library/external.js
584 /**
585 * WordPress dependencies
586 */
587
588
589 const external = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
590 xmlns: "http://www.w3.org/2000/svg",
591 viewBox: "0 0 24 24",
592 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
593 d: "M19.5 4.5h-7V6h4.44l-5.97 5.97 1.06 1.06L18 7.06v4.44h1.5v-7Zm-13 1a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-3H17v3a.5.5 0 0 1-.5.5h-10a.5.5 0 0 1-.5-.5v-10a.5.5 0 0 1 .5-.5h3V5.5h-3Z"
594 })
595 });
596 /* harmony default export */ const library_external = (external);
597
598 ;// external ["wp","keyboardShortcuts"]
599 const external_wp_keyboardShortcuts_namespaceObject = window["wp"]["keyboardShortcuts"];
600 ;// ./packages/customize-widgets/build-module/components/keyboard-shortcut-help-modal/config.js
601 /**
602 * WordPress dependencies
603 */
604
605 const textFormattingShortcuts = [{
606 keyCombination: {
607 modifier: 'primary',
608 character: 'b'
609 },
610 description: (0,external_wp_i18n_namespaceObject.__)('Make the selected text bold.')
611 }, {
612 keyCombination: {
613 modifier: 'primary',
614 character: 'i'
615 },
616 description: (0,external_wp_i18n_namespaceObject.__)('Make the selected text italic.')
617 }, {
618 keyCombination: {
619 modifier: 'primary',
620 character: 'k'
621 },
622 description: (0,external_wp_i18n_namespaceObject.__)('Convert the selected text into a link.')
623 }, {
624 keyCombination: {
625 modifier: 'primaryShift',
626 character: 'k'
627 },
628 description: (0,external_wp_i18n_namespaceObject.__)('Remove a link.')
629 }, {
630 keyCombination: {
631 character: '[['
632 },
633 description: (0,external_wp_i18n_namespaceObject.__)('Insert a link to a post or page.')
634 }, {
635 keyCombination: {
636 modifier: 'primary',
637 character: 'u'
638 },
639 description: (0,external_wp_i18n_namespaceObject.__)('Underline the selected text.')
640 }, {
641 keyCombination: {
642 modifier: 'access',
643 character: 'd'
644 },
645 description: (0,external_wp_i18n_namespaceObject.__)('Strikethrough the selected text.')
646 }, {
647 keyCombination: {
648 modifier: 'access',
649 character: 'x'
650 },
651 description: (0,external_wp_i18n_namespaceObject.__)('Make the selected text inline code.')
652 }, {
653 keyCombination: {
654 modifier: 'access',
655 character: '0'
656 },
657 aliases: [{
658 modifier: 'access',
659 character: '7'
660 }],
661 description: (0,external_wp_i18n_namespaceObject.__)('Convert the current heading to a paragraph.')
662 }, {
663 keyCombination: {
664 modifier: 'access',
665 character: '1-6'
666 },
667 description: (0,external_wp_i18n_namespaceObject.__)('Convert the current paragraph or heading to a heading of level 1 to 6.')
668 }, {
669 keyCombination: {
670 modifier: 'primaryShift',
671 character: 'SPACE'
672 },
673 description: (0,external_wp_i18n_namespaceObject.__)('Add non breaking space.')
674 }];
675
676 ;// ./packages/customize-widgets/build-module/components/keyboard-shortcut-help-modal/shortcut.js
677 /**
678 * WordPress dependencies
679 */
680
681
682
683 function KeyCombination({
684 keyCombination,
685 forceAriaLabel
686 }) {
687 const shortcut = keyCombination.modifier ? external_wp_keycodes_namespaceObject.displayShortcutList[keyCombination.modifier](keyCombination.character) : keyCombination.character;
688 const ariaLabel = keyCombination.modifier ? external_wp_keycodes_namespaceObject.shortcutAriaLabel[keyCombination.modifier](keyCombination.character) : keyCombination.character;
689 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("kbd", {
690 className: "customize-widgets-keyboard-shortcut-help-modal__shortcut-key-combination",
691 "aria-label": forceAriaLabel || ariaLabel,
692 children: (Array.isArray(shortcut) ? shortcut : [shortcut]).map((character, index) => {
693 if (character === '+') {
694 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_element_namespaceObject.Fragment, {
695 children: character
696 }, index);
697 }
698 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("kbd", {
699 className: "customize-widgets-keyboard-shortcut-help-modal__shortcut-key",
700 children: character
701 }, index);
702 })
703 });
704 }
705 function Shortcut({
706 description,
707 keyCombination,
708 aliases = [],
709 ariaLabel
710 }) {
711 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_ReactJSXRuntime_namespaceObject.Fragment, {
712 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", {
713 className: "customize-widgets-keyboard-shortcut-help-modal__shortcut-description",
714 children: description
715 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)("div", {
716 className: "customize-widgets-keyboard-shortcut-help-modal__shortcut-term",
717 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(KeyCombination, {
718 keyCombination: keyCombination,
719 forceAriaLabel: ariaLabel
720 }), aliases.map((alias, index) => /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(KeyCombination, {
721 keyCombination: alias,
722 forceAriaLabel: ariaLabel
723 }, index))]
724 })]
725 });
726 }
727 /* harmony default export */ const keyboard_shortcut_help_modal_shortcut = (Shortcut);
728
729 ;// ./packages/customize-widgets/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.js
730 /**
731 * WordPress dependencies
732 */
733
734
735
736 /**
737 * Internal dependencies
738 */
739
740
741 function DynamicShortcut({
742 name
743 }) {
744 const {
745 keyCombination,
746 description,
747 aliases
748 } = (0,external_wp_data_namespaceObject.useSelect)(select => {
749 const {
750 getShortcutKeyCombination,
751 getShortcutDescription,
752 getShortcutAliases
753 } = select(external_wp_keyboardShortcuts_namespaceObject.store);
754 return {
755 keyCombination: getShortcutKeyCombination(name),
756 aliases: getShortcutAliases(name),
757 description: getShortcutDescription(name)
758 };
759 }, [name]);
760 if (!keyCombination) {
761 return null;
762 }
763 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(keyboard_shortcut_help_modal_shortcut, {
764 keyCombination: keyCombination,
765 description: description,
766 aliases: aliases
767 });
768 }
769 /* harmony default export */ const dynamic_shortcut = (DynamicShortcut);
770
771 ;// ./packages/customize-widgets/build-module/components/keyboard-shortcut-help-modal/index.js
772 /**
773 * External dependencies
774 */
775
776
777 /**
778 * WordPress dependencies
779 */
780
781
782
783
784
785 /**
786 * Internal dependencies
787 */
788
789
790
791
792 const ShortcutList = ({
793 shortcuts
794 }) =>
795 /*#__PURE__*/
796 /*
797 * Disable reason: The `list` ARIA role is redundant but
798 * Safari+VoiceOver won't announce the list otherwise.
799 */
800 /* eslint-disable jsx-a11y/no-redundant-roles */
801 (0,external_ReactJSXRuntime_namespaceObject.jsx)("ul", {
802 className: "customize-widgets-keyboard-shortcut-help-modal__shortcut-list",
803 role: "list",
804 children: shortcuts.map((shortcut, index) => /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("li", {
805 className: "customize-widgets-keyboard-shortcut-help-modal__shortcut",
806 children: typeof shortcut === 'string' ? /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(dynamic_shortcut, {
807 name: shortcut
808 }) : /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(keyboard_shortcut_help_modal_shortcut, {
809 ...shortcut
810 })
811 }, index))
812 })
813 /* eslint-enable jsx-a11y/no-redundant-roles */;
814 const ShortcutSection = ({
815 title,
816 shortcuts,
817 className
818 }) => /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)("section", {
819 className: dist_clsx('customize-widgets-keyboard-shortcut-help-modal__section', className),
820 children: [!!title && /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("h2", {
821 className: "customize-widgets-keyboard-shortcut-help-modal__section-title",
822 children: title
823 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(ShortcutList, {
824 shortcuts: shortcuts
825 })]
826 });
827 const ShortcutCategorySection = ({
828 title,
829 categoryName,
830 additionalShortcuts = []
831 }) => {
832 const categoryShortcuts = (0,external_wp_data_namespaceObject.useSelect)(select => {
833 return select(external_wp_keyboardShortcuts_namespaceObject.store).getCategoryShortcuts(categoryName);
834 }, [categoryName]);
835 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(ShortcutSection, {
836 title: title,
837 shortcuts: categoryShortcuts.concat(additionalShortcuts)
838 });
839 };
840 function KeyboardShortcutHelpModal({
841 isModalActive,
842 toggleModal
843 }) {
844 const {
845 registerShortcut
846 } = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_keyboardShortcuts_namespaceObject.store);
847 registerShortcut({
848 name: 'core/customize-widgets/keyboard-shortcuts',
849 category: 'main',
850 description: (0,external_wp_i18n_namespaceObject.__)('Display these keyboard shortcuts.'),
851 keyCombination: {
852 modifier: 'access',
853 character: 'h'
854 }
855 });
856 (0,external_wp_keyboardShortcuts_namespaceObject.useShortcut)('core/customize-widgets/keyboard-shortcuts', toggleModal);
857 if (!isModalActive) {
858 return null;
859 }
860 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_wp_components_namespaceObject.Modal, {
861 className: "customize-widgets-keyboard-shortcut-help-modal",
862 title: (0,external_wp_i18n_namespaceObject.__)('Keyboard shortcuts'),
863 onRequestClose: toggleModal,
864 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(ShortcutSection, {
865 className: "customize-widgets-keyboard-shortcut-help-modal__main-shortcuts",
866 shortcuts: ['core/customize-widgets/keyboard-shortcuts']
867 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(ShortcutCategorySection, {
868 title: (0,external_wp_i18n_namespaceObject.__)('Global shortcuts'),
869 categoryName: "global"
870 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(ShortcutCategorySection, {
871 title: (0,external_wp_i18n_namespaceObject.__)('Selection shortcuts'),
872 categoryName: "selection"
873 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(ShortcutCategorySection, {
874 title: (0,external_wp_i18n_namespaceObject.__)('Block shortcuts'),
875 categoryName: "block",
876 additionalShortcuts: [{
877 keyCombination: {
878 character: '/'
879 },
880 description: (0,external_wp_i18n_namespaceObject.__)('Change the block type after adding a new paragraph.'),
881 /* translators: The forward-slash character. e.g. '/'. */
882 ariaLabel: (0,external_wp_i18n_namespaceObject.__)('Forward-slash')
883 }]
884 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(ShortcutSection, {
885 title: (0,external_wp_i18n_namespaceObject.__)('Text formatting'),
886 shortcuts: textFormattingShortcuts
887 })]
888 });
889 }
890
891 ;// ./packages/customize-widgets/build-module/components/more-menu/index.js
892 /**
893 * WordPress dependencies
894 */
895
896
897
898
899
900
901
902
903 /**
904 * Internal dependencies
905 */
906
907
908 function MoreMenu() {
909 const [isKeyboardShortcutsModalActive, setIsKeyboardShortcutsModalVisible] = (0,external_wp_element_namespaceObject.useState)(false);
910 const toggleKeyboardShortcutsModal = () => setIsKeyboardShortcutsModalVisible(!isKeyboardShortcutsModalActive);
911 (0,external_wp_keyboardShortcuts_namespaceObject.useShortcut)('core/customize-widgets/keyboard-shortcuts', toggleKeyboardShortcutsModal);
912 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_ReactJSXRuntime_namespaceObject.Fragment, {
913 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.ToolbarDropdownMenu, {
914 icon: more_vertical,
915 label: (0,external_wp_i18n_namespaceObject.__)('Options'),
916 popoverProps: {
917 placement: 'bottom-end',
918 className: 'more-menu-dropdown__content'
919 },
920 toggleProps: {
921 tooltipPosition: 'bottom',
922 size: 'compact'
923 },
924 children: () => /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_ReactJSXRuntime_namespaceObject.Fragment, {
925 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.MenuGroup, {
926 label: (0,external_wp_i18n_namespaceObject._x)('View', 'noun'),
927 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_preferences_namespaceObject.PreferenceToggleMenuItem, {
928 scope: "core/customize-widgets",
929 name: "fixedToolbar",
930 label: (0,external_wp_i18n_namespaceObject.__)('Top toolbar'),
931 info: (0,external_wp_i18n_namespaceObject.__)('Access all block and document tools in a single place'),
932 messageActivated: (0,external_wp_i18n_namespaceObject.__)('Top toolbar activated'),
933 messageDeactivated: (0,external_wp_i18n_namespaceObject.__)('Top toolbar deactivated')
934 })
935 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_wp_components_namespaceObject.MenuGroup, {
936 label: (0,external_wp_i18n_namespaceObject.__)('Tools'),
937 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.MenuItem, {
938 onClick: () => {
939 setIsKeyboardShortcutsModalVisible(true);
940 },
941 shortcut: external_wp_keycodes_namespaceObject.displayShortcut.access('h'),
942 children: (0,external_wp_i18n_namespaceObject.__)('Keyboard shortcuts')
943 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_preferences_namespaceObject.PreferenceToggleMenuItem, {
944 scope: "core/customize-widgets",
945 name: "welcomeGuide",
946 label: (0,external_wp_i18n_namespaceObject.__)('Welcome Guide')
947 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_wp_components_namespaceObject.MenuItem, {
948 role: "menuitem",
949 icon: library_external,
950 href: (0,external_wp_i18n_namespaceObject.__)('https://wordpress.org/documentation/article/block-based-widgets-editor/'),
951 target: "_blank",
952 rel: "noopener noreferrer",
953 children: [(0,external_wp_i18n_namespaceObject.__)('Help'), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.VisuallyHidden, {
954 as: "span",
955 children: /* translators: accessibility text */
956 (0,external_wp_i18n_namespaceObject.__)('(opens in a new tab)')
957 })]
958 })]
959 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.MenuGroup, {
960 label: (0,external_wp_i18n_namespaceObject.__)('Preferences'),
961 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_preferences_namespaceObject.PreferenceToggleMenuItem, {
962 scope: "core/customize-widgets",
963 name: "keepCaretInsideBlock",
964 label: (0,external_wp_i18n_namespaceObject.__)('Contain text cursor inside block'),
965 info: (0,external_wp_i18n_namespaceObject.__)('Aids screen readers by stopping text caret from leaving blocks.'),
966 messageActivated: (0,external_wp_i18n_namespaceObject.__)('Contain text cursor inside block activated'),
967 messageDeactivated: (0,external_wp_i18n_namespaceObject.__)('Contain text cursor inside block deactivated')
968 })
969 })]
970 })
971 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(KeyboardShortcutHelpModal, {
972 isModalActive: isKeyboardShortcutsModalActive,
973 toggleModal: toggleKeyboardShortcutsModal
974 })]
975 });
976 }
977
978 ;// ./packages/customize-widgets/build-module/components/header/index.js
979 /**
980 * External dependencies
981 */
982
983
984 /**
985 * WordPress dependencies
986 */
987
988
989
990
991
992
993
994 /**
995 * Internal dependencies
996 */
997
998
999
1000 function Header({
1001 sidebar,
1002 inserter,
1003 isInserterOpened,
1004 setIsInserterOpened,
1005 isFixedToolbarActive
1006 }) {
1007 const [[hasUndo, hasRedo], setUndoRedo] = (0,external_wp_element_namespaceObject.useState)([sidebar.hasUndo(), sidebar.hasRedo()]);
1008 const shortcut = (0,external_wp_keycodes_namespaceObject.isAppleOS)() ? external_wp_keycodes_namespaceObject.displayShortcut.primaryShift('z') : external_wp_keycodes_namespaceObject.displayShortcut.primary('y');
1009 (0,external_wp_element_namespaceObject.useEffect)(() => {
1010 return sidebar.subscribeHistory(() => {
1011 setUndoRedo([sidebar.hasUndo(), sidebar.hasRedo()]);
1012 });
1013 }, [sidebar]);
1014 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_ReactJSXRuntime_namespaceObject.Fragment, {
1015 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", {
1016 className: dist_clsx('customize-widgets-header', {
1017 'is-fixed-toolbar-active': isFixedToolbarActive
1018 }),
1019 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_wp_blockEditor_namespaceObject.NavigableToolbar, {
1020 className: "customize-widgets-header-toolbar",
1021 "aria-label": (0,external_wp_i18n_namespaceObject.__)('Document tools'),
1022 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.ToolbarButton, {
1023 icon: !(0,external_wp_i18n_namespaceObject.isRTL)() ? library_undo : library_redo
1024 /* translators: button label text should, if possible, be under 16 characters. */,
1025 label: (0,external_wp_i18n_namespaceObject.__)('Undo'),
1026 shortcut: external_wp_keycodes_namespaceObject.displayShortcut.primary('z'),
1027 disabled: !hasUndo,
1028 onClick: sidebar.undo,
1029 className: "customize-widgets-editor-history-button undo-button"
1030 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.ToolbarButton, {
1031 icon: !(0,external_wp_i18n_namespaceObject.isRTL)() ? library_redo : library_undo
1032 /* translators: button label text should, if possible, be under 16 characters. */,
1033 label: (0,external_wp_i18n_namespaceObject.__)('Redo'),
1034 shortcut: shortcut,
1035 disabled: !hasRedo,
1036 onClick: sidebar.redo,
1037 className: "customize-widgets-editor-history-button redo-button"
1038 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.ToolbarButton, {
1039 className: "customize-widgets-header-toolbar__inserter-toggle",
1040 isPressed: isInserterOpened,
1041 variant: "primary",
1042 icon: library_plus,
1043 label: (0,external_wp_i18n_namespaceObject._x)('Add block', 'Generic label for block inserter button'),
1044 onClick: () => {
1045 setIsInserterOpened(isOpen => !isOpen);
1046 }
1047 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(MoreMenu, {})]
1048 })
1049 }), (0,external_wp_element_namespaceObject.createPortal)(/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(components_inserter, {
1050 setIsOpened: setIsInserterOpened
1051 }), inserter.contentContainer[0])]
1052 });
1053 }
1054 /* harmony default export */ const header = (Header);
1055
1056 ;// ./packages/customize-widgets/build-module/components/inserter/use-inserter.js
1057 /**
1058 * WordPress dependencies
1059 */
1060
1061
1062
1063 /**
1064 * Internal dependencies
1065 */
1066
1067 function useInserter(inserter) {
1068 const isInserterOpened = (0,external_wp_data_namespaceObject.useSelect)(select => select(store).isInserterOpened(), []);
1069 const {
1070 setIsInserterOpened
1071 } = (0,external_wp_data_namespaceObject.useDispatch)(store);
1072 (0,external_wp_element_namespaceObject.useEffect)(() => {
1073 if (isInserterOpened) {
1074 inserter.open();
1075 } else {
1076 inserter.close();
1077 }
1078 }, [inserter, isInserterOpened]);
1079 return [isInserterOpened, (0,external_wp_element_namespaceObject.useCallback)(updater => {
1080 let isOpen = updater;
1081 if (typeof updater === 'function') {
1082 isOpen = updater((0,external_wp_data_namespaceObject.select)(store).isInserterOpened());
1083 }
1084 setIsInserterOpened(isOpen);
1085 }, [setIsInserterOpened])];
1086 }
1087
1088 // EXTERNAL MODULE: ./node_modules/fast-deep-equal/es6/index.js
1089 var es6 = __webpack_require__(7734);
1090 var es6_default = /*#__PURE__*/__webpack_require__.n(es6);
1091 ;// external ["wp","isShallowEqual"]
1092 const external_wp_isShallowEqual_namespaceObject = window["wp"]["isShallowEqual"];
1093 var external_wp_isShallowEqual_default = /*#__PURE__*/__webpack_require__.n(external_wp_isShallowEqual_namespaceObject);
1094 ;// ./packages/customize-widgets/build-module/utils.js
1095 // @ts-check
1096 /**
1097 * WordPress dependencies
1098 */
1099
1100
1101
1102 /**
1103 * Convert settingId to widgetId.
1104 *
1105 * @param {string} settingId The setting id.
1106 * @return {string} The widget id.
1107 */
1108 function settingIdToWidgetId(settingId) {
1109 const matches = settingId.match(/^widget_(.+)(?:\[(\d+)\])$/);
1110 if (matches) {
1111 const idBase = matches[1];
1112 const number = parseInt(matches[2], 10);
1113 return `${idBase}-${number}`;
1114 }
1115 return settingId;
1116 }
1117
1118 /**
1119 * Transform a block to a customizable widget.
1120 *
1121 * @param {WPBlock} block The block to be transformed from.
1122 * @param {Object} existingWidget The widget to be extended from.
1123 * @return {Object} The transformed widget.
1124 */
1125 function blockToWidget(block, existingWidget = null) {
1126 let widget;
1127 const isValidLegacyWidgetBlock = block.name === 'core/legacy-widget' && (block.attributes.id || block.attributes.instance);
1128 if (isValidLegacyWidgetBlock) {
1129 if (block.attributes.id) {
1130 // Widget that does not extend WP_Widget.
1131 widget = {
1132 id: block.attributes.id
1133 };
1134 } else {
1135 const {
1136 encoded,
1137 hash,
1138 raw,
1139 ...rest
1140 } = block.attributes.instance;
1141
1142 // Widget that extends WP_Widget.
1143 widget = {
1144 idBase: block.attributes.idBase,
1145 instance: {
1146 ...existingWidget?.instance,
1147 // Required only for the customizer.
1148 is_widget_customizer_js_value: true,
1149 encoded_serialized_instance: encoded,
1150 instance_hash_key: hash,
1151 raw_instance: raw,
1152 ...rest
1153 }
1154 };
1155 }
1156 } else {
1157 const instance = {
1158 content: (0,external_wp_blocks_namespaceObject.serialize)(block)
1159 };
1160 widget = {
1161 idBase: 'block',
1162 widgetClass: 'WP_Widget_Block',
1163 instance: {
1164 raw_instance: instance
1165 }
1166 };
1167 }
1168 const {
1169 form,
1170 rendered,
1171 ...restExistingWidget
1172 } = existingWidget || {};
1173 return {
1174 ...restExistingWidget,
1175 ...widget
1176 };
1177 }
1178
1179 /**
1180 * Transform a widget to a block.
1181 *
1182 * @param {Object} widget The widget to be transformed from.
1183 * @param {string} widget.id The widget id.
1184 * @param {string} widget.idBase The id base of the widget.
1185 * @param {number} widget.number The number/index of the widget.
1186 * @param {Object} widget.instance The instance of the widget.
1187 * @return {WPBlock} The transformed block.
1188 */
1189 function widgetToBlock({
1190 id,
1191 idBase,
1192 number,
1193 instance
1194 }) {
1195 let block;
1196 const {
1197 encoded_serialized_instance: encoded,
1198 instance_hash_key: hash,
1199 raw_instance: raw,
1200 ...rest
1201 } = instance;
1202 if (idBase === 'block') {
1203 var _raw$content;
1204 const parsedBlocks = (0,external_wp_blocks_namespaceObject.parse)((_raw$content = raw.content) !== null && _raw$content !== void 0 ? _raw$content : '', {
1205 __unstableSkipAutop: true
1206 });
1207 block = parsedBlocks.length ? parsedBlocks[0] : (0,external_wp_blocks_namespaceObject.createBlock)('core/paragraph', {});
1208 } else if (number) {
1209 // Widget that extends WP_Widget.
1210 block = (0,external_wp_blocks_namespaceObject.createBlock)('core/legacy-widget', {
1211 idBase,
1212 instance: {
1213 encoded,
1214 hash,
1215 raw,
1216 ...rest
1217 }
1218 });
1219 } else {
1220 // Widget that does not extend WP_Widget.
1221 block = (0,external_wp_blocks_namespaceObject.createBlock)('core/legacy-widget', {
1222 id
1223 });
1224 }
1225 return (0,external_wp_widgets_namespaceObject.addWidgetIdToBlock)(block, id);
1226 }
1227
1228 ;// ./packages/customize-widgets/build-module/components/sidebar-block-editor/use-sidebar-block-editor.js
1229 /**
1230 * External dependencies
1231 */
1232
1233
1234 /**
1235 * WordPress dependencies
1236 */
1237
1238
1239
1240
1241 /**
1242 * Internal dependencies
1243 */
1244
1245 function widgetsToBlocks(widgets) {
1246 return widgets.map(widget => widgetToBlock(widget));
1247 }
1248 function useSidebarBlockEditor(sidebar) {
1249 const [blocks, setBlocks] = (0,external_wp_element_namespaceObject.useState)(() => widgetsToBlocks(sidebar.getWidgets()));
1250 (0,external_wp_element_namespaceObject.useEffect)(() => {
1251 return sidebar.subscribe((prevWidgets, nextWidgets) => {
1252 setBlocks(prevBlocks => {
1253 const prevWidgetsMap = new Map(prevWidgets.map(widget => [widget.id, widget]));
1254 const prevBlocksMap = new Map(prevBlocks.map(block => [(0,external_wp_widgets_namespaceObject.getWidgetIdFromBlock)(block), block]));
1255 const nextBlocks = nextWidgets.map(nextWidget => {
1256 const prevWidget = prevWidgetsMap.get(nextWidget.id);
1257
1258 // Bail out updates.
1259 if (prevWidget && prevWidget === nextWidget) {
1260 return prevBlocksMap.get(nextWidget.id);
1261 }
1262 return widgetToBlock(nextWidget);
1263 });
1264
1265 // Bail out updates.
1266 if (external_wp_isShallowEqual_default()(prevBlocks, nextBlocks)) {
1267 return prevBlocks;
1268 }
1269 return nextBlocks;
1270 });
1271 });
1272 }, [sidebar]);
1273 const onChangeBlocks = (0,external_wp_element_namespaceObject.useCallback)(nextBlocks => {
1274 setBlocks(prevBlocks => {
1275 if (external_wp_isShallowEqual_default()(prevBlocks, nextBlocks)) {
1276 return prevBlocks;
1277 }
1278 const prevBlocksMap = new Map(prevBlocks.map(block => [(0,external_wp_widgets_namespaceObject.getWidgetIdFromBlock)(block), block]));
1279 const nextWidgets = nextBlocks.map(nextBlock => {
1280 const widgetId = (0,external_wp_widgets_namespaceObject.getWidgetIdFromBlock)(nextBlock);
1281
1282 // Update existing widgets.
1283 if (widgetId && prevBlocksMap.has(widgetId)) {
1284 const prevBlock = prevBlocksMap.get(widgetId);
1285 const prevWidget = sidebar.getWidget(widgetId);
1286
1287 // Bail out updates by returning the previous widgets.
1288 // Deep equality is necessary until the block editor's internals changes.
1289 if (es6_default()(nextBlock, prevBlock) && prevWidget) {
1290 return prevWidget;
1291 }
1292 return blockToWidget(nextBlock, prevWidget);
1293 }
1294
1295 // Add a new widget.
1296 return blockToWidget(nextBlock);
1297 });
1298
1299 // Bail out updates if the updated widgets are the same.
1300 if (external_wp_isShallowEqual_default()(sidebar.getWidgets(), nextWidgets)) {
1301 return prevBlocks;
1302 }
1303 const addedWidgetIds = sidebar.setWidgets(nextWidgets);
1304 return nextBlocks.reduce((updatedNextBlocks, nextBlock, index) => {
1305 const addedWidgetId = addedWidgetIds[index];
1306 if (addedWidgetId !== null) {
1307 // Only create a new instance if necessary to prevent
1308 // the whole editor from re-rendering on every edit.
1309 if (updatedNextBlocks === nextBlocks) {
1310 updatedNextBlocks = nextBlocks.slice();
1311 }
1312 updatedNextBlocks[index] = (0,external_wp_widgets_namespaceObject.addWidgetIdToBlock)(nextBlock, addedWidgetId);
1313 }
1314 return updatedNextBlocks;
1315 }, nextBlocks);
1316 });
1317 }, [sidebar]);
1318 return [blocks, onChangeBlocks, onChangeBlocks];
1319 }
1320
1321 ;// ./packages/customize-widgets/build-module/components/focus-control/index.js
1322 /**
1323 * WordPress dependencies
1324 */
1325
1326
1327 /**
1328 * Internal dependencies
1329 */
1330
1331
1332 const FocusControlContext = (0,external_wp_element_namespaceObject.createContext)();
1333 function FocusControl({
1334 api,
1335 sidebarControls,
1336 children
1337 }) {
1338 const [focusedWidgetIdRef, setFocusedWidgetIdRef] = (0,external_wp_element_namespaceObject.useState)({
1339 current: null
1340 });
1341 const focusWidget = (0,external_wp_element_namespaceObject.useCallback)(widgetId => {
1342 for (const sidebarControl of sidebarControls) {
1343 const widgets = sidebarControl.setting.get();
1344 if (widgets.includes(widgetId)) {
1345 sidebarControl.sectionInstance.expand({
1346 // Schedule it after the complete callback so that
1347 // it won't be overridden by the "Back" button focus.
1348 completeCallback() {
1349 // Create a "ref-like" object every time to ensure
1350 // the same widget id can also triggers the focus control.
1351 setFocusedWidgetIdRef({
1352 current: widgetId
1353 });
1354 }
1355 });
1356 break;
1357 }
1358 }
1359 }, [sidebarControls]);
1360 (0,external_wp_element_namespaceObject.useEffect)(() => {
1361 function handleFocus(settingId) {
1362 const widgetId = settingIdToWidgetId(settingId);
1363 focusWidget(widgetId);
1364 }
1365 let previewBound = false;
1366 function handleReady() {
1367 api.previewer.preview.bind('focus-control-for-setting', handleFocus);
1368 previewBound = true;
1369 }
1370 api.previewer.bind('ready', handleReady);
1371 return () => {
1372 api.previewer.unbind('ready', handleReady);
1373 if (previewBound) {
1374 api.previewer.preview.unbind('focus-control-for-setting', handleFocus);
1375 }
1376 };
1377 }, [api, focusWidget]);
1378 const context = (0,external_wp_element_namespaceObject.useMemo)(() => [focusedWidgetIdRef, focusWidget], [focusedWidgetIdRef, focusWidget]);
1379 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(FocusControlContext.Provider, {
1380 value: context,
1381 children: children
1382 });
1383 }
1384 const useFocusControl = () => (0,external_wp_element_namespaceObject.useContext)(FocusControlContext);
1385
1386 ;// ./packages/customize-widgets/build-module/components/focus-control/use-blocks-focus-control.js
1387 /**
1388 * WordPress dependencies
1389 */
1390
1391
1392
1393
1394
1395 /**
1396 * Internal dependencies
1397 */
1398
1399 function useBlocksFocusControl(blocks) {
1400 const {
1401 selectBlock
1402 } = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_blockEditor_namespaceObject.store);
1403 const [focusedWidgetIdRef] = useFocusControl();
1404 const blocksRef = (0,external_wp_element_namespaceObject.useRef)(blocks);
1405 (0,external_wp_element_namespaceObject.useEffect)(() => {
1406 blocksRef.current = blocks;
1407 }, [blocks]);
1408 (0,external_wp_element_namespaceObject.useEffect)(() => {
1409 if (focusedWidgetIdRef.current) {
1410 const focusedBlock = blocksRef.current.find(block => (0,external_wp_widgets_namespaceObject.getWidgetIdFromBlock)(block) === focusedWidgetIdRef.current);
1411 if (focusedBlock) {
1412 selectBlock(focusedBlock.clientId);
1413 // If the block is already being selected, the DOM node won't
1414 // get focused again automatically.
1415 // We select the DOM and focus it manually here.
1416 const blockNode = document.querySelector(`[data-block="${focusedBlock.clientId}"]`);
1417 blockNode?.focus();
1418 }
1419 }
1420 }, [focusedWidgetIdRef, selectBlock]);
1421 }
1422
1423 ;// external ["wp","privateApis"]
1424 const external_wp_privateApis_namespaceObject = window["wp"]["privateApis"];
1425 ;// ./packages/customize-widgets/build-module/lock-unlock.js
1426 /**
1427 * WordPress dependencies
1428 */
1429
1430 const {
1431 lock,
1432 unlock
1433 } = (0,external_wp_privateApis_namespaceObject.__dangerousOptInToUnstableAPIsOnlyForCoreModules)('I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.', '@wordpress/customize-widgets');
1434
1435 ;// ./packages/customize-widgets/build-module/components/sidebar-block-editor/sidebar-editor-provider.js
1436 /**
1437 * WordPress dependencies
1438 */
1439
1440
1441 /**
1442 * Internal dependencies
1443 */
1444
1445
1446
1447
1448 const {
1449 ExperimentalBlockEditorProvider
1450 } = unlock(external_wp_blockEditor_namespaceObject.privateApis);
1451 function SidebarEditorProvider({
1452 sidebar,
1453 settings,
1454 children
1455 }) {
1456 const [blocks, onInput, onChange] = useSidebarBlockEditor(sidebar);
1457 useBlocksFocusControl(blocks);
1458 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(ExperimentalBlockEditorProvider, {
1459 value: blocks,
1460 onInput: onInput,
1461 onChange: onChange,
1462 settings: settings,
1463 useSubRegistry: false,
1464 children: children
1465 });
1466 }
1467
1468 ;// ./packages/customize-widgets/build-module/components/welcome-guide/index.js
1469 /**
1470 * WordPress dependencies
1471 */
1472
1473
1474
1475
1476
1477 function WelcomeGuide({
1478 sidebar
1479 }) {
1480 const {
1481 toggle
1482 } = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_preferences_namespaceObject.store);
1483 const isEntirelyBlockWidgets = sidebar.getWidgets().every(widget => widget.id.startsWith('block-'));
1484 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)("div", {
1485 className: "customize-widgets-welcome-guide",
1486 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", {
1487 className: "customize-widgets-welcome-guide__image__wrapper",
1488 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)("picture", {
1489 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("source", {
1490 srcSet: "https://s.w.org/images/block-editor/welcome-editor.svg",
1491 media: "(prefers-reduced-motion: reduce)"
1492 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("img", {
1493 className: "customize-widgets-welcome-guide__image",
1494 src: "https://s.w.org/images/block-editor/welcome-editor.gif",
1495 width: "312",
1496 height: "240",
1497 alt: ""
1498 })]
1499 })
1500 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("h1", {
1501 className: "customize-widgets-welcome-guide__heading",
1502 children: (0,external_wp_i18n_namespaceObject.__)('Welcome to block Widgets')
1503 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("p", {
1504 className: "customize-widgets-welcome-guide__text",
1505 children: isEntirelyBlockWidgets ? (0,external_wp_i18n_namespaceObject.__)('Your theme provides different “block” areas for you to add and edit content. Try adding a search bar, social icons, or other types of blocks here and see how they’ll look on your site.') : (0,external_wp_i18n_namespaceObject.__)('You can now add any block to your site’s widget areas. Don’t worry, all of your favorite widgets still work flawlessly.')
1506 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Button, {
1507 size: "compact",
1508 variant: "primary",
1509 onClick: () => toggle('core/customize-widgets', 'welcomeGuide'),
1510 children: (0,external_wp_i18n_namespaceObject.__)('Got it')
1511 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("hr", {
1512 className: "customize-widgets-welcome-guide__separator"
1513 }), !isEntirelyBlockWidgets && /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)("p", {
1514 className: "customize-widgets-welcome-guide__more-info",
1515 children: [(0,external_wp_i18n_namespaceObject.__)('Want to stick with the old widgets?'), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("br", {}), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.ExternalLink, {
1516 href: (0,external_wp_i18n_namespaceObject.__)('https://wordpress.org/plugins/classic-widgets/'),
1517 children: (0,external_wp_i18n_namespaceObject.__)('Get the Classic Widgets plugin.')
1518 })]
1519 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)("p", {
1520 className: "customize-widgets-welcome-guide__more-info",
1521 children: [(0,external_wp_i18n_namespaceObject.__)('New to the block editor?'), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("br", {}), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.ExternalLink, {
1522 href: (0,external_wp_i18n_namespaceObject.__)('https://wordpress.org/documentation/article/wordpress-block-editor/'),
1523 children: (0,external_wp_i18n_namespaceObject.__)("Here's a detailed guide.")
1524 })]
1525 })]
1526 });
1527 }
1528
1529 ;// ./packages/customize-widgets/build-module/components/keyboard-shortcuts/index.js
1530 /**
1531 * WordPress dependencies
1532 */
1533
1534
1535
1536
1537
1538 function KeyboardShortcuts({
1539 undo,
1540 redo,
1541 save
1542 }) {
1543 (0,external_wp_keyboardShortcuts_namespaceObject.useShortcut)('core/customize-widgets/undo', event => {
1544 undo();
1545 event.preventDefault();
1546 });
1547 (0,external_wp_keyboardShortcuts_namespaceObject.useShortcut)('core/customize-widgets/redo', event => {
1548 redo();
1549 event.preventDefault();
1550 });
1551 (0,external_wp_keyboardShortcuts_namespaceObject.useShortcut)('core/customize-widgets/save', event => {
1552 event.preventDefault();
1553 save();
1554 });
1555 return null;
1556 }
1557 function KeyboardShortcutsRegister() {
1558 const {
1559 registerShortcut,
1560 unregisterShortcut
1561 } = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_keyboardShortcuts_namespaceObject.store);
1562 (0,external_wp_element_namespaceObject.useEffect)(() => {
1563 registerShortcut({
1564 name: 'core/customize-widgets/undo',
1565 category: 'global',
1566 description: (0,external_wp_i18n_namespaceObject.__)('Undo your last changes.'),
1567 keyCombination: {
1568 modifier: 'primary',
1569 character: 'z'
1570 }
1571 });
1572 registerShortcut({
1573 name: 'core/customize-widgets/redo',
1574 category: 'global',
1575 description: (0,external_wp_i18n_namespaceObject.__)('Redo your last undo.'),
1576 keyCombination: {
1577 modifier: 'primaryShift',
1578 character: 'z'
1579 },
1580 // Disable on Apple OS because it conflicts with the browser's
1581 // history shortcut. It's a fine alias for both Windows and Linux.
1582 // Since there's no conflict for Ctrl+Shift+Z on both Windows and
1583 // Linux, we keep it as the default for consistency.
1584 aliases: (0,external_wp_keycodes_namespaceObject.isAppleOS)() ? [] : [{
1585 modifier: 'primary',
1586 character: 'y'
1587 }]
1588 });
1589 registerShortcut({
1590 name: 'core/customize-widgets/save',
1591 category: 'global',
1592 description: (0,external_wp_i18n_namespaceObject.__)('Save your changes.'),
1593 keyCombination: {
1594 modifier: 'primary',
1595 character: 's'
1596 }
1597 });
1598 return () => {
1599 unregisterShortcut('core/customize-widgets/undo');
1600 unregisterShortcut('core/customize-widgets/redo');
1601 unregisterShortcut('core/customize-widgets/save');
1602 };
1603 }, [registerShortcut]);
1604 return null;
1605 }
1606 KeyboardShortcuts.Register = KeyboardShortcutsRegister;
1607 /* harmony default export */ const keyboard_shortcuts = (KeyboardShortcuts);
1608
1609 ;// ./packages/customize-widgets/build-module/components/block-appender/index.js
1610 /**
1611 * WordPress dependencies
1612 */
1613
1614
1615
1616
1617 function BlockAppender(props) {
1618 const ref = (0,external_wp_element_namespaceObject.useRef)();
1619 const isBlocksListEmpty = (0,external_wp_data_namespaceObject.useSelect)(select => select(external_wp_blockEditor_namespaceObject.store).getBlockCount() === 0);
1620
1621 // Move the focus to the block appender to prevent focus from
1622 // being lost when emptying the widget area.
1623 (0,external_wp_element_namespaceObject.useEffect)(() => {
1624 if (isBlocksListEmpty && ref.current) {
1625 const {
1626 ownerDocument
1627 } = ref.current;
1628 if (!ownerDocument.activeElement || ownerDocument.activeElement === ownerDocument.body) {
1629 ref.current.focus();
1630 }
1631 }
1632 }, [isBlocksListEmpty]);
1633 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.ButtonBlockAppender, {
1634 ...props,
1635 ref: ref
1636 });
1637 }
1638
1639 ;// ./packages/customize-widgets/build-module/components/sidebar-block-editor/index.js
1640 /**
1641 * WordPress dependencies
1642 */
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652 /**
1653 * Internal dependencies
1654 */
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664 const {
1665 ExperimentalBlockCanvas: BlockCanvas
1666 } = unlock(external_wp_blockEditor_namespaceObject.privateApis);
1667 const {
1668 BlockKeyboardShortcuts
1669 } = unlock(external_wp_blockLibrary_namespaceObject.privateApis);
1670 function SidebarBlockEditor({
1671 blockEditorSettings,
1672 sidebar,
1673 inserter,
1674 inspector
1675 }) {
1676 const [isInserterOpened, setIsInserterOpened] = useInserter(inserter);
1677 const isMediumViewport = (0,external_wp_compose_namespaceObject.useViewportMatch)('small');
1678 const {
1679 hasUploadPermissions,
1680 isFixedToolbarActive,
1681 keepCaretInsideBlock,
1682 isWelcomeGuideActive
1683 } = (0,external_wp_data_namespaceObject.useSelect)(select => {
1684 var _select$canUser;
1685 const {
1686 get
1687 } = select(external_wp_preferences_namespaceObject.store);
1688 return {
1689 hasUploadPermissions: (_select$canUser = select(external_wp_coreData_namespaceObject.store).canUser('create', {
1690 kind: 'root',
1691 name: 'media'
1692 })) !== null && _select$canUser !== void 0 ? _select$canUser : true,
1693 isFixedToolbarActive: !!get('core/customize-widgets', 'fixedToolbar'),
1694 keepCaretInsideBlock: !!get('core/customize-widgets', 'keepCaretInsideBlock'),
1695 isWelcomeGuideActive: !!get('core/customize-widgets', 'welcomeGuide')
1696 };
1697 }, []);
1698 const settings = (0,external_wp_element_namespaceObject.useMemo)(() => {
1699 let mediaUploadBlockEditor;
1700 if (hasUploadPermissions) {
1701 mediaUploadBlockEditor = ({
1702 onError,
1703 ...argumentsObject
1704 }) => {
1705 (0,external_wp_mediaUtils_namespaceObject.uploadMedia)({
1706 wpAllowedMimeTypes: blockEditorSettings.allowedMimeTypes,
1707 onError: ({
1708 message
1709 }) => onError(message),
1710 ...argumentsObject
1711 });
1712 };
1713 }
1714 return {
1715 ...blockEditorSettings,
1716 __experimentalSetIsInserterOpened: setIsInserterOpened,
1717 mediaUpload: mediaUploadBlockEditor,
1718 hasFixedToolbar: isFixedToolbarActive || !isMediumViewport,
1719 keepCaretInsideBlock,
1720 __unstableHasCustomAppender: true
1721 };
1722 }, [hasUploadPermissions, blockEditorSettings, isFixedToolbarActive, isMediumViewport, keepCaretInsideBlock, setIsInserterOpened]);
1723 if (isWelcomeGuideActive) {
1724 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(WelcomeGuide, {
1725 sidebar: sidebar
1726 });
1727 }
1728 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_ReactJSXRuntime_namespaceObject.Fragment, {
1729 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(keyboard_shortcuts.Register, {}), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(BlockKeyboardShortcuts, {}), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(SidebarEditorProvider, {
1730 sidebar: sidebar,
1731 settings: settings,
1732 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(keyboard_shortcuts, {
1733 undo: sidebar.undo,
1734 redo: sidebar.redo,
1735 save: sidebar.save
1736 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(header, {
1737 sidebar: sidebar,
1738 inserter: inserter,
1739 isInserterOpened: isInserterOpened,
1740 setIsInserterOpened: setIsInserterOpened,
1741 isFixedToolbarActive: isFixedToolbarActive || !isMediumViewport
1742 }), (isFixedToolbarActive || !isMediumViewport) && /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.BlockToolbar, {
1743 hideDragHandle: true
1744 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(BlockCanvas, {
1745 shouldIframe: false,
1746 styles: settings.defaultEditorStyles,
1747 height: "100%",
1748 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.BlockList, {
1749 renderAppender: BlockAppender
1750 })
1751 }), (0,external_wp_element_namespaceObject.createPortal)(
1752 /*#__PURE__*/
1753 // This is a temporary hack to prevent button component inside <BlockInspector>
1754 // from submitting form when type="button" is not specified.
1755 (0,external_ReactJSXRuntime_namespaceObject.jsx)("form", {
1756 onSubmit: event => event.preventDefault(),
1757 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.BlockInspector, {})
1758 }), inspector.contentContainer[0])]
1759 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.__unstableBlockSettingsMenuFirstItem, {
1760 children: ({
1761 onClose
1762 }) => /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(block_inspector_button, {
1763 inspector: inspector,
1764 closeMenu: onClose
1765 })
1766 })]
1767 });
1768 }
1769
1770 ;// ./packages/customize-widgets/build-module/components/sidebar-controls/index.js
1771 /**
1772 * WordPress dependencies
1773 */
1774
1775
1776 const SidebarControlsContext = (0,external_wp_element_namespaceObject.createContext)();
1777 function SidebarControls({
1778 sidebarControls,
1779 activeSidebarControl,
1780 children
1781 }) {
1782 const context = (0,external_wp_element_namespaceObject.useMemo)(() => ({
1783 sidebarControls,
1784 activeSidebarControl
1785 }), [sidebarControls, activeSidebarControl]);
1786 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(SidebarControlsContext.Provider, {
1787 value: context,
1788 children: children
1789 });
1790 }
1791 function useSidebarControls() {
1792 const {
1793 sidebarControls
1794 } = (0,external_wp_element_namespaceObject.useContext)(SidebarControlsContext);
1795 return sidebarControls;
1796 }
1797 function useActiveSidebarControl() {
1798 const {
1799 activeSidebarControl
1800 } = (0,external_wp_element_namespaceObject.useContext)(SidebarControlsContext);
1801 return activeSidebarControl;
1802 }
1803
1804 ;// ./packages/customize-widgets/build-module/components/customize-widgets/use-clear-selected-block.js
1805 /**
1806 * WordPress dependencies
1807 */
1808
1809
1810
1811
1812 /**
1813 * We can't just use <BlockSelectionClearer> because the customizer has
1814 * many root nodes rather than just one in the post editor.
1815 * We need to listen to the focus events in all those roots, and also in
1816 * the preview iframe.
1817 * This hook will clear the selected block when focusing outside the editor,
1818 * with a few exceptions:
1819 * 1. Focusing on popovers.
1820 * 2. Focusing on the inspector.
1821 * 3. Focusing on any modals/dialogs.
1822 * These cases are normally triggered by user interactions from the editor,
1823 * not by explicitly focusing outside the editor, hence no need for clearing.
1824 *
1825 * @param {Object} sidebarControl The sidebar control instance.
1826 * @param {Object} popoverRef The ref object of the popover node container.
1827 */
1828 function useClearSelectedBlock(sidebarControl, popoverRef) {
1829 const {
1830 hasSelectedBlock,
1831 hasMultiSelection
1832 } = (0,external_wp_data_namespaceObject.useSelect)(external_wp_blockEditor_namespaceObject.store);
1833 const {
1834 clearSelectedBlock
1835 } = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_blockEditor_namespaceObject.store);
1836 (0,external_wp_element_namespaceObject.useEffect)(() => {
1837 if (popoverRef.current && sidebarControl) {
1838 const inspector = sidebarControl.inspector;
1839 const container = sidebarControl.container[0];
1840 const ownerDocument = container.ownerDocument;
1841 const ownerWindow = ownerDocument.defaultView;
1842 function handleClearSelectedBlock(element) {
1843 if (
1844 // 1. Make sure there are blocks being selected.
1845 (hasSelectedBlock() || hasMultiSelection()) &&
1846 // 2. The element should exist in the DOM (not deleted).
1847 element && ownerDocument.contains(element) &&
1848 // 3. It should also not exist in the container, the popover, nor the dialog.
1849 !container.contains(element) && !popoverRef.current.contains(element) && !element.closest('[role="dialog"]') &&
1850 // 4. The inspector should not be opened.
1851 !inspector.expanded()) {
1852 clearSelectedBlock();
1853 }
1854 }
1855
1856 // Handle mouse down in the same document.
1857 function handleMouseDown(event) {
1858 handleClearSelectedBlock(event.target);
1859 }
1860 // Handle focusing outside the current document, like to iframes.
1861 function handleBlur() {
1862 handleClearSelectedBlock(ownerDocument.activeElement);
1863 }
1864 ownerDocument.addEventListener('mousedown', handleMouseDown);
1865 ownerWindow.addEventListener('blur', handleBlur);
1866 return () => {
1867 ownerDocument.removeEventListener('mousedown', handleMouseDown);
1868 ownerWindow.removeEventListener('blur', handleBlur);
1869 };
1870 }
1871 }, [popoverRef, sidebarControl, hasSelectedBlock, hasMultiSelection, clearSelectedBlock]);
1872 }
1873
1874 ;// ./packages/customize-widgets/build-module/components/customize-widgets/index.js
1875 /**
1876 * WordPress dependencies
1877 */
1878
1879
1880
1881 /**
1882 * Internal dependencies
1883 */
1884
1885
1886
1887
1888
1889
1890 function CustomizeWidgets({
1891 api,
1892 sidebarControls,
1893 blockEditorSettings
1894 }) {
1895 const [activeSidebarControl, setActiveSidebarControl] = (0,external_wp_element_namespaceObject.useState)(null);
1896 const parentContainer = document.getElementById('customize-theme-controls');
1897 const popoverRef = (0,external_wp_element_namespaceObject.useRef)();
1898 useClearSelectedBlock(activeSidebarControl, popoverRef);
1899 (0,external_wp_element_namespaceObject.useEffect)(() => {
1900 const unsubscribers = sidebarControls.map(sidebarControl => sidebarControl.subscribe(expanded => {
1901 if (expanded) {
1902 setActiveSidebarControl(sidebarControl);
1903 }
1904 }));
1905 return () => {
1906 unsubscribers.forEach(unsubscriber => unsubscriber());
1907 };
1908 }, [sidebarControls]);
1909 const activeSidebar = activeSidebarControl && (0,external_wp_element_namespaceObject.createPortal)(/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(ErrorBoundary, {
1910 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(SidebarBlockEditor, {
1911 blockEditorSettings: blockEditorSettings,
1912 sidebar: activeSidebarControl.sidebarAdapter,
1913 inserter: activeSidebarControl.inserter,
1914 inspector: activeSidebarControl.inspector
1915 }, activeSidebarControl.id)
1916 }), activeSidebarControl.container[0]);
1917
1918 // We have to portal this to the parent of both the editor and the inspector,
1919 // so that the popovers will appear above both of them.
1920 const popover = parentContainer && (0,external_wp_element_namespaceObject.createPortal)(/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", {
1921 className: "customize-widgets-popover",
1922 ref: popoverRef,
1923 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Popover.Slot, {})
1924 }), parentContainer);
1925 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.SlotFillProvider, {
1926 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(SidebarControls, {
1927 sidebarControls: sidebarControls,
1928 activeSidebarControl: activeSidebarControl,
1929 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(FocusControl, {
1930 api: api,
1931 sidebarControls: sidebarControls,
1932 children: [activeSidebar, popover]
1933 })
1934 })
1935 });
1936 }
1937
1938 ;// ./packages/customize-widgets/build-module/controls/inspector-section.js
1939 function getInspectorSection() {
1940 const {
1941 wp: {
1942 customize
1943 }
1944 } = window;
1945 return class InspectorSection extends customize.Section {
1946 constructor(id, options) {
1947 super(id, options);
1948 this.parentSection = options.parentSection;
1949 this.returnFocusWhenClose = null;
1950 this._isOpen = false;
1951 }
1952 get isOpen() {
1953 return this._isOpen;
1954 }
1955 set isOpen(value) {
1956 this._isOpen = value;
1957 this.triggerActiveCallbacks();
1958 }
1959 ready() {
1960 this.contentContainer[0].classList.add('customize-widgets-layout__inspector');
1961 }
1962 isContextuallyActive() {
1963 return this.isOpen;
1964 }
1965 onChangeExpanded(expanded, args) {
1966 super.onChangeExpanded(expanded, args);
1967 if (this.parentSection && !args.unchanged) {
1968 if (expanded) {
1969 this.parentSection.collapse({
1970 manualTransition: true
1971 });
1972 } else {
1973 this.parentSection.expand({
1974 manualTransition: true,
1975 completeCallback: () => {
1976 // Return focus after finishing the transition.
1977 if (this.returnFocusWhenClose && !this.contentContainer[0].contains(this.returnFocusWhenClose)) {
1978 this.returnFocusWhenClose.focus();
1979 }
1980 }
1981 });
1982 }
1983 }
1984 }
1985 open({
1986 returnFocusWhenClose
1987 } = {}) {
1988 this.isOpen = true;
1989 this.returnFocusWhenClose = returnFocusWhenClose;
1990 this.expand({
1991 allowMultiple: true
1992 });
1993 }
1994 close() {
1995 this.collapse({
1996 allowMultiple: true
1997 });
1998 }
1999 collapse(options) {
2000 // Overridden collapse() function. Mostly call the parent collapse(), but also
2001 // move our .isOpen to false.
2002 // Initially, I tried tracking this with onChangeExpanded(), but it doesn't work
2003 // because the block settings sidebar is a layer "on top of" the G editor sidebar.
2004 //
2005 // For example, when closing the block settings sidebar, the G
2006 // editor sidebar would display, and onChangeExpanded in
2007 // inspector-section would run with expanded=true, but I want
2008 // isOpen to be false when the block settings is closed.
2009 this.isOpen = false;
2010 super.collapse(options);
2011 }
2012 triggerActiveCallbacks() {
2013 // Manually fire the callbacks associated with moving this.active
2014 // from false to true. "active" is always true for this section,
2015 // and "isContextuallyActive" reflects if the block settings
2016 // sidebar is currently visible, that is, it has replaced the main
2017 // Gutenberg view.
2018 // The WP customizer only checks ".isContextuallyActive()" when
2019 // ".active" changes values. But our ".active" never changes value.
2020 // The WP customizer never foresaw a section being used a way we
2021 // fit the block settings sidebar into a section. By manually
2022 // triggering the "this.active" callbacks, we force the WP
2023 // customizer to query our .isContextuallyActive() function and
2024 // update its view of our status.
2025 this.active.callbacks.fireWith(this.active, [false, true]);
2026 }
2027 };
2028 }
2029
2030 ;// ./packages/customize-widgets/build-module/controls/sidebar-section.js
2031 /**
2032 * WordPress dependencies
2033 */
2034
2035
2036 /**
2037 * Internal dependencies
2038 */
2039
2040 const getInspectorSectionId = sidebarId => `widgets-inspector-${sidebarId}`;
2041 function getSidebarSection() {
2042 const {
2043 wp: {
2044 customize
2045 }
2046 } = window;
2047 const reduceMotionMediaQuery = window.matchMedia('(prefers-reduced-motion: reduce)');
2048 let isReducedMotion = reduceMotionMediaQuery.matches;
2049 reduceMotionMediaQuery.addEventListener('change', event => {
2050 isReducedMotion = event.matches;
2051 });
2052 return class SidebarSection extends customize.Section {
2053 ready() {
2054 const InspectorSection = getInspectorSection();
2055 this.inspector = new InspectorSection(getInspectorSectionId(this.id), {
2056 title: (0,external_wp_i18n_namespaceObject.__)('Block Settings'),
2057 parentSection: this,
2058 customizeAction: [(0,external_wp_i18n_namespaceObject.__)('Customizing'), (0,external_wp_i18n_namespaceObject.__)('Widgets'), this.params.title].join('')
2059 });
2060 customize.section.add(this.inspector);
2061 this.contentContainer[0].classList.add('customize-widgets__sidebar-section');
2062 }
2063 hasSubSectionOpened() {
2064 return this.inspector.expanded();
2065 }
2066 onChangeExpanded(expanded, _args) {
2067 const controls = this.controls();
2068 const args = {
2069 ..._args,
2070 completeCallback() {
2071 controls.forEach(control => {
2072 control.onChangeSectionExpanded?.(expanded, args);
2073 });
2074 _args.completeCallback?.();
2075 }
2076 };
2077 if (args.manualTransition) {
2078 if (expanded) {
2079 this.contentContainer.addClass(['busy', 'open']);
2080 this.contentContainer.removeClass('is-sub-section-open');
2081 this.contentContainer.closest('.wp-full-overlay').addClass('section-open');
2082 } else {
2083 this.contentContainer.addClass(['busy', 'is-sub-section-open']);
2084 this.contentContainer.closest('.wp-full-overlay').addClass('section-open');
2085 this.contentContainer.removeClass('open');
2086 }
2087 const handleTransitionEnd = () => {
2088 this.contentContainer.removeClass('busy');
2089 args.completeCallback();
2090 };
2091 if (isReducedMotion) {
2092 handleTransitionEnd();
2093 } else {
2094 this.contentContainer.one('transitionend', handleTransitionEnd);
2095 }
2096 } else {
2097 super.onChangeExpanded(expanded, args);
2098 }
2099 }
2100 };
2101 }
2102
2103 ;// ./packages/customize-widgets/build-module/components/sidebar-block-editor/sidebar-adapter.js
2104 /* wp:polyfill */
2105 /**
2106 * Internal dependencies
2107 */
2108
2109 const {
2110 wp
2111 } = window;
2112 function parseWidgetId(widgetId) {
2113 const matches = widgetId.match(/^(.+)-(\d+)$/);
2114 if (matches) {
2115 return {
2116 idBase: matches[1],
2117 number: parseInt(matches[2], 10)
2118 };
2119 }
2120
2121 // Likely an old single widget.
2122 return {
2123 idBase: widgetId
2124 };
2125 }
2126 function widgetIdToSettingId(widgetId) {
2127 const {
2128 idBase,
2129 number
2130 } = parseWidgetId(widgetId);
2131 if (number) {
2132 return `widget_${idBase}[${number}]`;
2133 }
2134 return `widget_${idBase}`;
2135 }
2136
2137 /**
2138 * This is a custom debounce function to call different callbacks depending on
2139 * whether it's the _leading_ call or not.
2140 *
2141 * @param {Function} leading The callback that gets called first.
2142 * @param {Function} callback The callback that gets called after the first time.
2143 * @param {number} timeout The debounced time in milliseconds.
2144 * @return {Function} The debounced function.
2145 */
2146 function debounce(leading, callback, timeout) {
2147 let isLeading = false;
2148 let timerID;
2149 function debounced(...args) {
2150 const result = (isLeading ? callback : leading).apply(this, args);
2151 isLeading = true;
2152 clearTimeout(timerID);
2153 timerID = setTimeout(() => {
2154 isLeading = false;
2155 }, timeout);
2156 return result;
2157 }
2158 debounced.cancel = () => {
2159 isLeading = false;
2160 clearTimeout(timerID);
2161 };
2162 return debounced;
2163 }
2164 class SidebarAdapter {
2165 constructor(setting, api) {
2166 this.setting = setting;
2167 this.api = api;
2168 this.locked = false;
2169 this.widgetsCache = new WeakMap();
2170 this.subscribers = new Set();
2171 this.history = [this._getWidgetIds().map(widgetId => this.getWidget(widgetId))];
2172 this.historyIndex = 0;
2173 this.historySubscribers = new Set();
2174 // Debounce the input for 1 second.
2175 this._debounceSetHistory = debounce(this._pushHistory, this._replaceHistory, 1000);
2176 this.setting.bind(this._handleSettingChange.bind(this));
2177 this.api.bind('change', this._handleAllSettingsChange.bind(this));
2178 this.undo = this.undo.bind(this);
2179 this.redo = this.redo.bind(this);
2180 this.save = this.save.bind(this);
2181 }
2182 subscribe(callback) {
2183 this.subscribers.add(callback);
2184 return () => {
2185 this.subscribers.delete(callback);
2186 };
2187 }
2188 getWidgets() {
2189 return this.history[this.historyIndex];
2190 }
2191 _emit(...args) {
2192 for (const callback of this.subscribers) {
2193 callback(...args);
2194 }
2195 }
2196 _getWidgetIds() {
2197 return this.setting.get();
2198 }
2199 _pushHistory() {
2200 this.history = [...this.history.slice(0, this.historyIndex + 1), this._getWidgetIds().map(widgetId => this.getWidget(widgetId))];
2201 this.historyIndex += 1;
2202 this.historySubscribers.forEach(listener => listener());
2203 }
2204 _replaceHistory() {
2205 this.history[this.historyIndex] = this._getWidgetIds().map(widgetId => this.getWidget(widgetId));
2206 }
2207 _handleSettingChange() {
2208 if (this.locked) {
2209 return;
2210 }
2211 const prevWidgets = this.getWidgets();
2212 this._pushHistory();
2213 this._emit(prevWidgets, this.getWidgets());
2214 }
2215 _handleAllSettingsChange(setting) {
2216 if (this.locked) {
2217 return;
2218 }
2219 if (!setting.id.startsWith('widget_')) {
2220 return;
2221 }
2222 const widgetId = settingIdToWidgetId(setting.id);
2223 if (!this.setting.get().includes(widgetId)) {
2224 return;
2225 }
2226 const prevWidgets = this.getWidgets();
2227 this._pushHistory();
2228 this._emit(prevWidgets, this.getWidgets());
2229 }
2230 _createWidget(widget) {
2231 const widgetModel = wp.customize.Widgets.availableWidgets.findWhere({
2232 id_base: widget.idBase
2233 });
2234 let number = widget.number;
2235 if (widgetModel.get('is_multi') && !number) {
2236 widgetModel.set('multi_number', widgetModel.get('multi_number') + 1);
2237 number = widgetModel.get('multi_number');
2238 }
2239 const settingId = number ? `widget_${widget.idBase}[${number}]` : `widget_${widget.idBase}`;
2240 const settingArgs = {
2241 transport: wp.customize.Widgets.data.selectiveRefreshableWidgets[widgetModel.get('id_base')] ? 'postMessage' : 'refresh',
2242 previewer: this.setting.previewer
2243 };
2244 const setting = this.api.create(settingId, settingId, '', settingArgs);
2245 setting.set(widget.instance);
2246 const widgetId = settingIdToWidgetId(settingId);
2247 return widgetId;
2248 }
2249 _removeWidget(widget) {
2250 const settingId = widgetIdToSettingId(widget.id);
2251 const setting = this.api(settingId);
2252 if (setting) {
2253 const instance = setting.get();
2254 this.widgetsCache.delete(instance);
2255 }
2256 this.api.remove(settingId);
2257 }
2258 _updateWidget(widget) {
2259 const prevWidget = this.getWidget(widget.id);
2260
2261 // Bail out update if nothing changed.
2262 if (prevWidget === widget) {
2263 return widget.id;
2264 }
2265
2266 // Update existing setting if only the widget's instance changed.
2267 if (prevWidget.idBase && widget.idBase && prevWidget.idBase === widget.idBase) {
2268 const settingId = widgetIdToSettingId(widget.id);
2269 this.api(settingId).set(widget.instance);
2270 return widget.id;
2271 }
2272
2273 // Otherwise delete and re-create.
2274 this._removeWidget(widget);
2275 return this._createWidget(widget);
2276 }
2277 getWidget(widgetId) {
2278 if (!widgetId) {
2279 return null;
2280 }
2281 const {
2282 idBase,
2283 number
2284 } = parseWidgetId(widgetId);
2285 const settingId = widgetIdToSettingId(widgetId);
2286 const setting = this.api(settingId);
2287 if (!setting) {
2288 return null;
2289 }
2290 const instance = setting.get();
2291 if (this.widgetsCache.has(instance)) {
2292 return this.widgetsCache.get(instance);
2293 }
2294 const widget = {
2295 id: widgetId,
2296 idBase,
2297 number,
2298 instance
2299 };
2300 this.widgetsCache.set(instance, widget);
2301 return widget;
2302 }
2303 _updateWidgets(nextWidgets) {
2304 this.locked = true;
2305 const addedWidgetIds = [];
2306 const nextWidgetIds = nextWidgets.map(nextWidget => {
2307 if (nextWidget.id && this.getWidget(nextWidget.id)) {
2308 addedWidgetIds.push(null);
2309 return this._updateWidget(nextWidget);
2310 }
2311 const widgetId = this._createWidget(nextWidget);
2312 addedWidgetIds.push(widgetId);
2313 return widgetId;
2314 });
2315 const deletedWidgets = this.getWidgets().filter(widget => !nextWidgetIds.includes(widget.id));
2316 deletedWidgets.forEach(widget => this._removeWidget(widget));
2317 this.setting.set(nextWidgetIds);
2318 this.locked = false;
2319 return addedWidgetIds;
2320 }
2321 setWidgets(nextWidgets) {
2322 const addedWidgetIds = this._updateWidgets(nextWidgets);
2323 this._debounceSetHistory();
2324 return addedWidgetIds;
2325 }
2326
2327 /**
2328 * Undo/Redo related features
2329 */
2330 hasUndo() {
2331 return this.historyIndex > 0;
2332 }
2333 hasRedo() {
2334 return this.historyIndex < this.history.length - 1;
2335 }
2336 _seek(historyIndex) {
2337 const currentWidgets = this.getWidgets();
2338 this.historyIndex = historyIndex;
2339 const widgets = this.history[this.historyIndex];
2340 this._updateWidgets(widgets);
2341 this._emit(currentWidgets, this.getWidgets());
2342 this.historySubscribers.forEach(listener => listener());
2343 this._debounceSetHistory.cancel();
2344 }
2345 undo() {
2346 if (!this.hasUndo()) {
2347 return;
2348 }
2349 this._seek(this.historyIndex - 1);
2350 }
2351 redo() {
2352 if (!this.hasRedo()) {
2353 return;
2354 }
2355 this._seek(this.historyIndex + 1);
2356 }
2357 subscribeHistory(listener) {
2358 this.historySubscribers.add(listener);
2359 return () => {
2360 this.historySubscribers.delete(listener);
2361 };
2362 }
2363 save() {
2364 this.api.previewer.save();
2365 }
2366 }
2367
2368 ;// external ["wp","dom"]
2369 const external_wp_dom_namespaceObject = window["wp"]["dom"];
2370 ;// ./packages/customize-widgets/build-module/controls/inserter-outer-section.js
2371 /**
2372 * WordPress dependencies
2373 */
2374
2375
2376
2377
2378 /**
2379 * Internal dependencies
2380 */
2381
2382 function getInserterOuterSection() {
2383 const {
2384 wp: {
2385 customize
2386 }
2387 } = window;
2388 const OuterSection = customize.OuterSection;
2389 // Override the OuterSection class to handle multiple outer sections.
2390 // It closes all the other outer sections whenever one is opened.
2391 // The result is that at most one outer section can be opened at the same time.
2392 customize.OuterSection = class extends OuterSection {
2393 onChangeExpanded(expanded, args) {
2394 if (expanded) {
2395 customize.section.each(section => {
2396 if (section.params.type === 'outer' && section.id !== this.id) {
2397 if (section.expanded()) {
2398 section.collapse();
2399 }
2400 }
2401 });
2402 }
2403 return super.onChangeExpanded(expanded, args);
2404 }
2405 };
2406 // Handle constructor so that "params.type" can be correctly pointed to "outer".
2407 customize.sectionConstructor.outer = customize.OuterSection;
2408 return class InserterOuterSection extends customize.OuterSection {
2409 constructor(...args) {
2410 super(...args);
2411
2412 // This is necessary since we're creating a new class which is not identical to the original OuterSection.
2413 // @See https://github.com/WordPress/wordpress-develop/blob/42b05c397c50d9dc244083eff52991413909d4bd/src/js/_enqueues/wp/customize/controls.js#L1427-L1436
2414 this.params.type = 'outer';
2415 this.activeElementBeforeExpanded = null;
2416 const ownerWindow = this.contentContainer[0].ownerDocument.defaultView;
2417
2418 // Handle closing the inserter when pressing the Escape key.
2419 ownerWindow.addEventListener('keydown', event => {
2420 if (this.expanded() && (event.keyCode === external_wp_keycodes_namespaceObject.ESCAPE || event.code === 'Escape') && !event.defaultPrevented) {
2421 event.preventDefault();
2422 event.stopPropagation();
2423 (0,external_wp_data_namespaceObject.dispatch)(store).setIsInserterOpened(false);
2424 }
2425 },
2426 // Use capture mode to make this run before other event listeners.
2427 true);
2428 this.contentContainer.addClass('widgets-inserter');
2429
2430 // Set a flag if the state is being changed from open() or close().
2431 // Don't propagate the event if it's an internal action to prevent infinite loop.
2432 this.isFromInternalAction = false;
2433 this.expanded.bind(() => {
2434 if (!this.isFromInternalAction) {
2435 // Propagate the event to React to sync the state.
2436 (0,external_wp_data_namespaceObject.dispatch)(store).setIsInserterOpened(this.expanded());
2437 }
2438 this.isFromInternalAction = false;
2439 });
2440 }
2441 open() {
2442 if (!this.expanded()) {
2443 const contentContainer = this.contentContainer[0];
2444 this.activeElementBeforeExpanded = contentContainer.ownerDocument.activeElement;
2445 this.isFromInternalAction = true;
2446 this.expand({
2447 completeCallback() {
2448 // We have to do this in a "completeCallback" or else the elements will not yet be visible/tabbable.
2449 // The first one should be the close button,
2450 // we want to skip it and choose the second one instead, which is the search box.
2451 const searchBox = external_wp_dom_namespaceObject.focus.tabbable.find(contentContainer)[1];
2452 if (searchBox) {
2453 searchBox.focus();
2454 }
2455 }
2456 });
2457 }
2458 }
2459 close() {
2460 if (this.expanded()) {
2461 const contentContainer = this.contentContainer[0];
2462 const activeElement = contentContainer.ownerDocument.activeElement;
2463 this.isFromInternalAction = true;
2464 this.collapse({
2465 completeCallback() {
2466 // Return back the focus when closing the inserter.
2467 // Only do this if the active element which triggers the action is inside the inserter,
2468 // (the close button for instance). In that case the focus will be lost.
2469 // Otherwise, we don't hijack the focus when the user is focusing on other elements
2470 // (like the quick inserter).
2471 if (contentContainer.contains(activeElement)) {
2472 // Return back the focus when closing the inserter.
2473 if (this.activeElementBeforeExpanded) {
2474 this.activeElementBeforeExpanded.focus();
2475 }
2476 }
2477 }
2478 });
2479 }
2480 }
2481 };
2482 }
2483
2484 ;// ./packages/customize-widgets/build-module/controls/sidebar-control.js
2485 /* wp:polyfill */
2486 /**
2487 * WordPress dependencies
2488 */
2489
2490
2491 /**
2492 * Internal dependencies
2493 */
2494
2495
2496
2497 const getInserterId = controlId => `widgets-inserter-${controlId}`;
2498 function getSidebarControl() {
2499 const {
2500 wp: {
2501 customize
2502 }
2503 } = window;
2504 return class SidebarControl extends customize.Control {
2505 constructor(...args) {
2506 super(...args);
2507 this.subscribers = new Set();
2508 }
2509 ready() {
2510 const InserterOuterSection = getInserterOuterSection();
2511 this.inserter = new InserterOuterSection(getInserterId(this.id), {});
2512 customize.section.add(this.inserter);
2513 this.sectionInstance = customize.section(this.section());
2514 this.inspector = this.sectionInstance.inspector;
2515 this.sidebarAdapter = new SidebarAdapter(this.setting, customize);
2516 }
2517 subscribe(callback) {
2518 this.subscribers.add(callback);
2519 return () => {
2520 this.subscribers.delete(callback);
2521 };
2522 }
2523 onChangeSectionExpanded(expanded, args) {
2524 if (!args.unchanged) {
2525 // Close the inserter when the section collapses.
2526 if (!expanded) {
2527 (0,external_wp_data_namespaceObject.dispatch)(store).setIsInserterOpened(false);
2528 }
2529 this.subscribers.forEach(subscriber => subscriber(expanded, args));
2530 }
2531 }
2532 };
2533 }
2534
2535 ;// ./packages/customize-widgets/build-module/filters/move-to-sidebar.js
2536 /**
2537 * WordPress dependencies
2538 */
2539
2540
2541
2542
2543
2544
2545 /**
2546 * Internal dependencies
2547 */
2548
2549
2550
2551
2552 const withMoveToSidebarToolbarItem = (0,external_wp_compose_namespaceObject.createHigherOrderComponent)(BlockEdit => props => {
2553 let widgetId = (0,external_wp_widgets_namespaceObject.getWidgetIdFromBlock)(props);
2554 const sidebarControls = useSidebarControls();
2555 const activeSidebarControl = useActiveSidebarControl();
2556 const hasMultipleSidebars = sidebarControls?.length > 1;
2557 const blockName = props.name;
2558 const clientId = props.clientId;
2559 const canInsertBlockInSidebar = (0,external_wp_data_namespaceObject.useSelect)(select => {
2560 // Use an empty string to represent the root block list, which
2561 // in the customizer editor represents a sidebar/widget area.
2562 return select(external_wp_blockEditor_namespaceObject.store).canInsertBlockType(blockName, '');
2563 }, [blockName]);
2564 const block = (0,external_wp_data_namespaceObject.useSelect)(select => select(external_wp_blockEditor_namespaceObject.store).getBlock(clientId), [clientId]);
2565 const {
2566 removeBlock
2567 } = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_blockEditor_namespaceObject.store);
2568 const [, focusWidget] = useFocusControl();
2569 function moveToSidebar(sidebarControlId) {
2570 const newSidebarControl = sidebarControls.find(sidebarControl => sidebarControl.id === sidebarControlId);
2571 if (widgetId) {
2572 /**
2573 * If there's a widgetId, move it to the other sidebar.
2574 */
2575 const oldSetting = activeSidebarControl.setting;
2576 const newSetting = newSidebarControl.setting;
2577 oldSetting(oldSetting().filter(id => id !== widgetId));
2578 newSetting([...newSetting(), widgetId]);
2579 } else {
2580 /**
2581 * If there isn't a widgetId, it's most likely a inner block.
2582 * First, remove the block in the original sidebar,
2583 * then, create a new widget in the new sidebar and get back its widgetId.
2584 */
2585 const sidebarAdapter = newSidebarControl.sidebarAdapter;
2586 removeBlock(clientId);
2587 const addedWidgetIds = sidebarAdapter.setWidgets([...sidebarAdapter.getWidgets(), blockToWidget(block)]);
2588 // The last non-null id is the added widget's id.
2589 widgetId = addedWidgetIds.reverse().find(id => !!id);
2590 }
2591
2592 // Move focus to the moved widget and expand the sidebar.
2593 focusWidget(widgetId);
2594 }
2595 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_ReactJSXRuntime_namespaceObject.Fragment, {
2596 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(BlockEdit, {
2597 ...props
2598 }, "edit"), hasMultipleSidebars && canInsertBlockInSidebar && /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.BlockControls, {
2599 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_widgets_namespaceObject.MoveToWidgetArea, {
2600 widgetAreas: sidebarControls.map(sidebarControl => ({
2601 id: sidebarControl.id,
2602 name: sidebarControl.params.label,
2603 description: sidebarControl.params.description
2604 })),
2605 currentWidgetAreaId: activeSidebarControl?.id,
2606 onSelect: moveToSidebar
2607 })
2608 })]
2609 });
2610 }, 'withMoveToSidebarToolbarItem');
2611 (0,external_wp_hooks_namespaceObject.addFilter)('editor.BlockEdit', 'core/customize-widgets/block-edit', withMoveToSidebarToolbarItem);
2612
2613 ;// ./packages/customize-widgets/build-module/filters/replace-media-upload.js
2614 /**
2615 * WordPress dependencies
2616 */
2617
2618
2619 const replaceMediaUpload = () => external_wp_mediaUtils_namespaceObject.MediaUpload;
2620 (0,external_wp_hooks_namespaceObject.addFilter)('editor.MediaUpload', 'core/edit-widgets/replace-media-upload', replaceMediaUpload);
2621
2622 ;// ./packages/customize-widgets/build-module/filters/wide-widget-display.js
2623 /**
2624 * WordPress dependencies
2625 */
2626
2627
2628
2629 const {
2630 wp: wide_widget_display_wp
2631 } = window;
2632 const withWideWidgetDisplay = (0,external_wp_compose_namespaceObject.createHigherOrderComponent)(BlockEdit => props => {
2633 var _wp$customize$Widgets;
2634 const {
2635 idBase
2636 } = props.attributes;
2637 const isWide = (_wp$customize$Widgets = wide_widget_display_wp.customize.Widgets.data.availableWidgets.find(widget => widget.id_base === idBase)?.is_wide) !== null && _wp$customize$Widgets !== void 0 ? _wp$customize$Widgets : false;
2638 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(BlockEdit, {
2639 ...props,
2640 isWide: isWide
2641 }, "edit");
2642 }, 'withWideWidgetDisplay');
2643 (0,external_wp_hooks_namespaceObject.addFilter)('editor.BlockEdit', 'core/customize-widgets/wide-widget-display', withWideWidgetDisplay);
2644
2645 ;// ./packages/customize-widgets/build-module/filters/index.js
2646 /**
2647 * Internal dependencies
2648 */
2649
2650
2651
2652
2653 ;// ./packages/customize-widgets/build-module/index.js
2654 /**
2655 * WordPress dependencies
2656 */
2657
2658
2659
2660
2661
2662
2663
2664
2665 /**
2666 * Internal dependencies
2667 */
2668
2669
2670
2671
2672
2673
2674 const {
2675 wp: build_module_wp
2676 } = window;
2677 const DISABLED_BLOCKS = ['core/more', 'core/block', 'core/freeform', 'core/template-part'];
2678 const ENABLE_EXPERIMENTAL_FSE_BLOCKS = false;
2679 const {
2680 registerCoreBlockBindingsSources
2681 } = unlock(external_wp_editor_namespaceObject.privateApis);
2682
2683 /**
2684 * Initializes the widgets block editor in the customizer.
2685 *
2686 * @param {string} editorName The editor name.
2687 * @param {Object} blockEditorSettings Block editor settings.
2688 */
2689 function initialize(editorName, blockEditorSettings) {
2690 (0,external_wp_data_namespaceObject.dispatch)(external_wp_preferences_namespaceObject.store).setDefaults('core/customize-widgets', {
2691 fixedToolbar: false,
2692 welcomeGuide: true
2693 });
2694 (0,external_wp_data_namespaceObject.dispatch)(external_wp_blocks_namespaceObject.store).reapplyBlockTypeFilters();
2695 const coreBlocks = (0,external_wp_blockLibrary_namespaceObject.__experimentalGetCoreBlocks)().filter(block => {
2696 return !(DISABLED_BLOCKS.includes(block.name) || block.name.startsWith('core/post') || block.name.startsWith('core/query') || block.name.startsWith('core/site') || block.name.startsWith('core/navigation'));
2697 });
2698 (0,external_wp_blockLibrary_namespaceObject.registerCoreBlocks)(coreBlocks);
2699 registerCoreBlockBindingsSources();
2700 (0,external_wp_widgets_namespaceObject.registerLegacyWidgetBlock)();
2701 if (true) {
2702 (0,external_wp_blockLibrary_namespaceObject.__experimentalRegisterExperimentalCoreBlocks)({
2703 enableFSEBlocks: ENABLE_EXPERIMENTAL_FSE_BLOCKS
2704 });
2705 }
2706 (0,external_wp_widgets_namespaceObject.registerLegacyWidgetVariations)(blockEditorSettings);
2707 (0,external_wp_widgets_namespaceObject.registerWidgetGroupBlock)();
2708
2709 // As we are unregistering `core/freeform` to avoid the Classic block, we must
2710 // replace it with something as the default freeform content handler. Failure to
2711 // do this will result in errors in the default block parser.
2712 // see: https://github.com/WordPress/gutenberg/issues/33097
2713 (0,external_wp_blocks_namespaceObject.setFreeformContentHandlerName)('core/html');
2714 const SidebarControl = getSidebarControl(blockEditorSettings);
2715 build_module_wp.customize.sectionConstructor.sidebar = getSidebarSection();
2716 build_module_wp.customize.controlConstructor.sidebar_block_editor = SidebarControl;
2717 const container = document.createElement('div');
2718 document.body.appendChild(container);
2719 build_module_wp.customize.bind('ready', () => {
2720 const sidebarControls = [];
2721 build_module_wp.customize.control.each(control => {
2722 if (control instanceof SidebarControl) {
2723 sidebarControls.push(control);
2724 }
2725 });
2726 (0,external_wp_element_namespaceObject.createRoot)(container).render(/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_element_namespaceObject.StrictMode, {
2727 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(CustomizeWidgets, {
2728 api: build_module_wp.customize,
2729 sidebarControls: sidebarControls,
2730 blockEditorSettings: blockEditorSettings
2731 })
2732 }));
2733 });
2734 }
2735
2736
2737 (window.wp = window.wp || {}).customizeWidgets = __webpack_exports__;
2738 /******/ })()
2739 ;