| 1 |
/******/ (function() { // webpackBootstrap |
| 2 |
/******/ var __webpack_modules__ = ({ |
| 3 |
|
| 4 |
/***/ 4403: |
| 5 |
/***/ (function(module, exports) { |
| 6 |
|
| 7 |
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/*! |
| 8 |
Copyright (c) 2018 Jed Watson. |
| 9 |
Licensed under the MIT License (MIT), see |
| 10 |
http://jedwatson.github.io/classnames |
| 11 |
*/ |
| 12 |
/* global define */ |
| 13 |
|
| 14 |
(function () { |
| 15 |
'use strict'; |
| 16 |
|
| 17 |
var hasOwn = {}.hasOwnProperty; |
| 18 |
|
| 19 |
function classNames() { |
| 20 |
var classes = []; |
| 21 |
|
| 22 |
for (var i = 0; i < arguments.length; i++) { |
| 23 |
var arg = arguments[i]; |
| 24 |
if (!arg) continue; |
| 25 |
|
| 26 |
var argType = typeof arg; |
| 27 |
|
| 28 |
if (argType === 'string' || argType === 'number') { |
| 29 |
classes.push(arg); |
| 30 |
} else if (Array.isArray(arg)) { |
| 31 |
if (arg.length) { |
| 32 |
var inner = classNames.apply(null, arg); |
| 33 |
if (inner) { |
| 34 |
classes.push(inner); |
| 35 |
} |
| 36 |
} |
| 37 |
} else if (argType === 'object') { |
| 38 |
if (arg.toString === Object.prototype.toString) { |
| 39 |
for (var key in arg) { |
| 40 |
if (hasOwn.call(arg, key) && arg[key]) { |
| 41 |
classes.push(key); |
| 42 |
} |
| 43 |
} |
| 44 |
} else { |
| 45 |
classes.push(arg.toString()); |
| 46 |
} |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
return classes.join(' '); |
| 51 |
} |
| 52 |
|
| 53 |
if ( true && module.exports) { |
| 54 |
classNames.default = classNames; |
| 55 |
module.exports = classNames; |
| 56 |
} else if (true) { |
| 57 |
// register as 'classnames', consistent with npm package name |
| 58 |
!(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = (function () { |
| 59 |
return classNames; |
| 60 |
}).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), |
| 61 |
__WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); |
| 62 |
} else {} |
| 63 |
}()); |
| 64 |
|
| 65 |
|
| 66 |
/***/ }) |
| 67 |
|
| 68 |
/******/ }); |
| 69 |
/************************************************************************/ |
| 70 |
/******/ // The module cache |
| 71 |
/******/ var __webpack_module_cache__ = {}; |
| 72 |
/******/ |
| 73 |
/******/ // The require function |
| 74 |
/******/ function __webpack_require__(moduleId) { |
| 75 |
/******/ // Check if module is in cache |
| 76 |
/******/ var cachedModule = __webpack_module_cache__[moduleId]; |
| 77 |
/******/ if (cachedModule !== undefined) { |
| 78 |
/******/ return cachedModule.exports; |
| 79 |
/******/ } |
| 80 |
/******/ // Create a new module (and put it into the cache) |
| 81 |
/******/ var module = __webpack_module_cache__[moduleId] = { |
| 82 |
/******/ // no module.id needed |
| 83 |
/******/ // no module.loaded needed |
| 84 |
/******/ exports: {} |
| 85 |
/******/ }; |
| 86 |
/******/ |
| 87 |
/******/ // Execute the module function |
| 88 |
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); |
| 89 |
/******/ |
| 90 |
/******/ // Return the exports of the module |
| 91 |
/******/ return module.exports; |
| 92 |
/******/ } |
| 93 |
/******/ |
| 94 |
/************************************************************************/ |
| 95 |
/******/ /* webpack/runtime/compat get default export */ |
| 96 |
/******/ !function() { |
| 97 |
/******/ // getDefaultExport function for compatibility with non-harmony modules |
| 98 |
/******/ __webpack_require__.n = function(module) { |
| 99 |
/******/ var getter = module && module.__esModule ? |
| 100 |
/******/ function() { return module['default']; } : |
| 101 |
/******/ function() { return module; }; |
| 102 |
/******/ __webpack_require__.d(getter, { a: getter }); |
| 103 |
/******/ return getter; |
| 104 |
/******/ }; |
| 105 |
/******/ }(); |
| 106 |
/******/ |
| 107 |
/******/ /* webpack/runtime/define property getters */ |
| 108 |
/******/ !function() { |
| 109 |
/******/ // define getter functions for harmony exports |
| 110 |
/******/ __webpack_require__.d = function(exports, definition) { |
| 111 |
/******/ for(var key in definition) { |
| 112 |
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { |
| 113 |
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); |
| 114 |
/******/ } |
| 115 |
/******/ } |
| 116 |
/******/ }; |
| 117 |
/******/ }(); |
| 118 |
/******/ |
| 119 |
/******/ /* webpack/runtime/hasOwnProperty shorthand */ |
| 120 |
/******/ !function() { |
| 121 |
/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } |
| 122 |
/******/ }(); |
| 123 |
/******/ |
| 124 |
/******/ /* webpack/runtime/make namespace object */ |
| 125 |
/******/ !function() { |
| 126 |
/******/ // define __esModule on exports |
| 127 |
/******/ __webpack_require__.r = function(exports) { |
| 128 |
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { |
| 129 |
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); |
| 130 |
/******/ } |
| 131 |
/******/ Object.defineProperty(exports, '__esModule', { value: true }); |
| 132 |
/******/ }; |
| 133 |
/******/ }(); |
| 134 |
/******/ |
| 135 |
/************************************************************************/ |
| 136 |
var __webpack_exports__ = {}; |
| 137 |
// This entry need to be wrapped in an IIFE because it need to be in strict mode. |
| 138 |
!function() { |
| 139 |
"use strict"; |
| 140 |
// ESM COMPAT FLAG |
| 141 |
__webpack_require__.r(__webpack_exports__); |
| 142 |
|
| 143 |
// EXPORTS |
| 144 |
__webpack_require__.d(__webpack_exports__, { |
| 145 |
"MoveToWidgetArea": function() { return /* reexport */ MoveToWidgetArea; }, |
| 146 |
"addWidgetIdToBlock": function() { return /* reexport */ addWidgetIdToBlock; }, |
| 147 |
"getWidgetIdFromBlock": function() { return /* reexport */ getWidgetIdFromBlock; }, |
| 148 |
"registerLegacyWidgetBlock": function() { return /* binding */ registerLegacyWidgetBlock; }, |
| 149 |
"registerLegacyWidgetVariations": function() { return /* reexport */ registerLegacyWidgetVariations; }, |
| 150 |
"registerWidgetGroupBlock": function() { return /* binding */ registerWidgetGroupBlock; } |
| 151 |
}); |
| 152 |
|
| 153 |
// NAMESPACE OBJECT: ./packages/widgets/build-module/blocks/legacy-widget/index.js |
| 154 |
var legacy_widget_namespaceObject = {}; |
| 155 |
__webpack_require__.r(legacy_widget_namespaceObject); |
| 156 |
__webpack_require__.d(legacy_widget_namespaceObject, { |
| 157 |
"metadata": function() { return metadata; }, |
| 158 |
"name": function() { return legacy_widget_name; }, |
| 159 |
"settings": function() { return settings; } |
| 160 |
}); |
| 161 |
|
| 162 |
// NAMESPACE OBJECT: ./packages/widgets/build-module/blocks/widget-group/index.js |
| 163 |
var widget_group_namespaceObject = {}; |
| 164 |
__webpack_require__.r(widget_group_namespaceObject); |
| 165 |
__webpack_require__.d(widget_group_namespaceObject, { |
| 166 |
"metadata": function() { return widget_group_metadata; }, |
| 167 |
"name": function() { return widget_group_name; }, |
| 168 |
"settings": function() { return widget_group_settings; } |
| 169 |
}); |
| 170 |
|
| 171 |
;// CONCATENATED MODULE: external ["wp","blocks"] |
| 172 |
var external_wp_blocks_namespaceObject = window["wp"]["blocks"]; |
| 173 |
;// CONCATENATED MODULE: external ["wp","element"] |
| 174 |
var external_wp_element_namespaceObject = window["wp"]["element"]; |
| 175 |
;// CONCATENATED MODULE: external ["wp","primitives"] |
| 176 |
var external_wp_primitives_namespaceObject = window["wp"]["primitives"]; |
| 177 |
;// CONCATENATED MODULE: ./packages/icons/build-module/library/widget.js |
| 178 |
|
| 179 |
|
| 180 |
/** |
| 181 |
* WordPress dependencies |
| 182 |
*/ |
| 183 |
|
| 184 |
const widget = (0,external_wp_element_namespaceObject.createElement)(external_wp_primitives_namespaceObject.SVG, { |
| 185 |
xmlns: "http://www.w3.org/2000/svg", |
| 186 |
viewBox: "0 0 24 24" |
| 187 |
}, (0,external_wp_element_namespaceObject.createElement)(external_wp_primitives_namespaceObject.Path, { |
| 188 |
d: "M6 3H8V5H16V3H18V5C19.1046 5 20 5.89543 20 7V19C20 20.1046 19.1046 21 18 21H6C4.89543 21 4 20.1046 4 19V7C4 5.89543 4.89543 5 6 5V3ZM18 6.5H6C5.72386 6.5 5.5 6.72386 5.5 7V8H18.5V7C18.5 6.72386 18.2761 6.5 18 6.5ZM18.5 9.5H5.5V19C5.5 19.2761 5.72386 19.5 6 19.5H18C18.2761 19.5 18.5 19.2761 18.5 19V9.5ZM11 11H13V13H11V11ZM7 11V13H9V11H7ZM15 13V11H17V13H15Z" |
| 189 |
})); |
| 190 |
/* harmony default export */ var library_widget = (widget); |
| 191 |
|
| 192 |
// EXTERNAL MODULE: ./node_modules/classnames/index.js |
| 193 |
var classnames = __webpack_require__(4403); |
| 194 |
var classnames_default = /*#__PURE__*/__webpack_require__.n(classnames); |
| 195 |
;// CONCATENATED MODULE: external ["wp","blockEditor"] |
| 196 |
var external_wp_blockEditor_namespaceObject = window["wp"]["blockEditor"]; |
| 197 |
;// CONCATENATED MODULE: external ["wp","components"] |
| 198 |
var external_wp_components_namespaceObject = window["wp"]["components"]; |
| 199 |
;// CONCATENATED MODULE: ./packages/icons/build-module/library/brush.js |
| 200 |
|
| 201 |
|
| 202 |
/** |
| 203 |
* WordPress dependencies |
| 204 |
*/ |
| 205 |
|
| 206 |
const brush = (0,external_wp_element_namespaceObject.createElement)(external_wp_primitives_namespaceObject.SVG, { |
| 207 |
xmlns: "http://www.w3.org/2000/svg", |
| 208 |
viewBox: "0 0 24 24" |
| 209 |
}, (0,external_wp_element_namespaceObject.createElement)(external_wp_primitives_namespaceObject.Path, { |
| 210 |
d: "M4 20h8v-1.5H4V20zM18.9 3.5c-.6-.6-1.5-.6-2.1 0l-7.2 7.2c-.4-.1-.7 0-1.1.1-.5.2-1.5.7-1.9 2.2-.4 1.7-.8 2.2-1.1 2.7-.1.1-.2.3-.3.4l-.6 1.1H6c2 0 3.4-.4 4.7-1.4.8-.6 1.2-1.4 1.3-2.3 0-.3 0-.5-.1-.7L19 5.7c.5-.6.5-1.6-.1-2.2zM9.7 14.7c-.7.5-1.5.8-2.4 1 .2-.5.5-1.2.8-2.3.2-.6.4-1 .8-1.1.5-.1 1 .1 1.3.3.2.2.3.5.2.8 0 .3-.1.9-.7 1.3z" |
| 211 |
})); |
| 212 |
/* harmony default export */ var library_brush = (brush); |
| 213 |
|
| 214 |
;// CONCATENATED MODULE: external ["wp","i18n"] |
| 215 |
var external_wp_i18n_namespaceObject = window["wp"]["i18n"]; |
| 216 |
;// CONCATENATED MODULE: external ["wp","data"] |
| 217 |
var external_wp_data_namespaceObject = window["wp"]["data"]; |
| 218 |
;// CONCATENATED MODULE: external ["wp","coreData"] |
| 219 |
var external_wp_coreData_namespaceObject = window["wp"]["coreData"]; |
| 220 |
;// CONCATENATED MODULE: ./packages/widgets/build-module/blocks/legacy-widget/edit/widget-type-selector.js |
| 221 |
|
| 222 |
|
| 223 |
/** |
| 224 |
* WordPress dependencies |
| 225 |
*/ |
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
function WidgetTypeSelector(_ref) { |
| 232 |
let { |
| 233 |
selectedId, |
| 234 |
onSelect |
| 235 |
} = _ref; |
| 236 |
const widgetTypes = (0,external_wp_data_namespaceObject.useSelect)(select => { |
| 237 |
var _select$getSettings$w, _select$getSettings, _select$getWidgetType; |
| 238 |
|
| 239 |
const hiddenIds = (_select$getSettings$w = (_select$getSettings = select(external_wp_blockEditor_namespaceObject.store).getSettings()) === null || _select$getSettings === void 0 ? void 0 : _select$getSettings.widgetTypesToHideFromLegacyWidgetBlock) !== null && _select$getSettings$w !== void 0 ? _select$getSettings$w : []; |
| 240 |
return (_select$getWidgetType = select(external_wp_coreData_namespaceObject.store).getWidgetTypes({ |
| 241 |
per_page: -1 |
| 242 |
})) === null || _select$getWidgetType === void 0 ? void 0 : _select$getWidgetType.filter(widgetType => !hiddenIds.includes(widgetType.id)); |
| 243 |
}, []); |
| 244 |
|
| 245 |
if (!widgetTypes) { |
| 246 |
return (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Spinner, null); |
| 247 |
} |
| 248 |
|
| 249 |
if (widgetTypes.length === 0) { |
| 250 |
return (0,external_wp_i18n_namespaceObject.__)('There are no widgets available.'); |
| 251 |
} |
| 252 |
|
| 253 |
return (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.SelectControl, { |
| 254 |
__nextHasNoMarginBottom: true, |
| 255 |
label: (0,external_wp_i18n_namespaceObject.__)('Select a legacy widget to display:'), |
| 256 |
value: selectedId !== null && selectedId !== void 0 ? selectedId : '', |
| 257 |
options: [{ |
| 258 |
value: '', |
| 259 |
label: (0,external_wp_i18n_namespaceObject.__)('Select widget') |
| 260 |
}, ...widgetTypes.map(widgetType => ({ |
| 261 |
value: widgetType.id, |
| 262 |
label: widgetType.name |
| 263 |
}))], |
| 264 |
onChange: value => { |
| 265 |
if (value) { |
| 266 |
const selected = widgetTypes.find(widgetType => widgetType.id === value); |
| 267 |
onSelect({ |
| 268 |
selectedId: selected.id, |
| 269 |
isMulti: selected.is_multi |
| 270 |
}); |
| 271 |
} else { |
| 272 |
onSelect({ |
| 273 |
selectedId: null |
| 274 |
}); |
| 275 |
} |
| 276 |
} |
| 277 |
}); |
| 278 |
} |
| 279 |
|
| 280 |
;// CONCATENATED MODULE: ./packages/widgets/build-module/blocks/legacy-widget/edit/inspector-card.js |
| 281 |
|
| 282 |
function InspectorCard(_ref) { |
| 283 |
let { |
| 284 |
name, |
| 285 |
description |
| 286 |
} = _ref; |
| 287 |
return (0,external_wp_element_namespaceObject.createElement)("div", { |
| 288 |
className: "wp-block-legacy-widget-inspector-card" |
| 289 |
}, (0,external_wp_element_namespaceObject.createElement)("h3", { |
| 290 |
className: "wp-block-legacy-widget-inspector-card__name" |
| 291 |
}, name), (0,external_wp_element_namespaceObject.createElement)("span", null, description)); |
| 292 |
} |
| 293 |
|
| 294 |
;// CONCATENATED MODULE: external ["wp","notices"] |
| 295 |
var external_wp_notices_namespaceObject = window["wp"]["notices"]; |
| 296 |
;// CONCATENATED MODULE: external ["wp","compose"] |
| 297 |
var external_wp_compose_namespaceObject = window["wp"]["compose"]; |
| 298 |
;// CONCATENATED MODULE: external ["wp","apiFetch"] |
| 299 |
var external_wp_apiFetch_namespaceObject = window["wp"]["apiFetch"]; |
| 300 |
var external_wp_apiFetch_default = /*#__PURE__*/__webpack_require__.n(external_wp_apiFetch_namespaceObject); |
| 301 |
;// CONCATENATED MODULE: ./packages/widgets/build-module/blocks/legacy-widget/edit/control.js |
| 302 |
/** |
| 303 |
* WordPress dependencies |
| 304 |
*/ |
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
/** |
| 309 |
* An API for creating and loading a widget control (a <div class="widget"> |
| 310 |
* element) that is compatible with most third party widget scripts. By not |
| 311 |
* using React for this, we ensure that we have complete contorl over the DOM |
| 312 |
* and do not accidentally remove any elements that a third party widget script |
| 313 |
* has attached an event listener to. |
| 314 |
* |
| 315 |
* @property {Element} element The control's DOM element. |
| 316 |
*/ |
| 317 |
|
| 318 |
class Control { |
| 319 |
/** |
| 320 |
* Creates and loads a new control. |
| 321 |
* |
| 322 |
* @access public |
| 323 |
* @param {Object} params |
| 324 |
* @param {string} params.id |
| 325 |
* @param {string} params.idBase |
| 326 |
* @param {Object} params.instance |
| 327 |
* @param {Function} params.onChangeInstance |
| 328 |
* @param {Function} params.onChangeHasPreview |
| 329 |
* @param {Function} params.onError |
| 330 |
*/ |
| 331 |
constructor(_ref) { |
| 332 |
let { |
| 333 |
id, |
| 334 |
idBase, |
| 335 |
instance, |
| 336 |
onChangeInstance, |
| 337 |
onChangeHasPreview, |
| 338 |
onError |
| 339 |
} = _ref; |
| 340 |
this.id = id; |
| 341 |
this.idBase = idBase; |
| 342 |
this._instance = instance; |
| 343 |
this._hasPreview = null; |
| 344 |
this.onChangeInstance = onChangeInstance; |
| 345 |
this.onChangeHasPreview = onChangeHasPreview; |
| 346 |
this.onError = onError; // We can't use the real widget number as this is calculated by the |
| 347 |
// server and we may not ever *actually* save this widget. Instead, use |
| 348 |
// a fake but unique number. |
| 349 |
|
| 350 |
this.number = ++lastNumber; |
| 351 |
this.handleFormChange = (0,external_wp_compose_namespaceObject.debounce)(this.handleFormChange.bind(this), 200); |
| 352 |
this.handleFormSubmit = this.handleFormSubmit.bind(this); |
| 353 |
this.initDOM(); |
| 354 |
this.bindEvents(); |
| 355 |
this.loadContent(); |
| 356 |
} |
| 357 |
/** |
| 358 |
* Clean up the control so that it can be garabge collected. |
| 359 |
* |
| 360 |
* @access public |
| 361 |
*/ |
| 362 |
|
| 363 |
|
| 364 |
destroy() { |
| 365 |
this.unbindEvents(); |
| 366 |
this.element.remove(); // TODO: How do we make third party widget scripts remove their event |
| 367 |
// listeners? |
| 368 |
} |
| 369 |
/** |
| 370 |
* Creates the control's DOM structure. |
| 371 |
* |
| 372 |
* @access private |
| 373 |
*/ |
| 374 |
|
| 375 |
|
| 376 |
initDOM() { |
| 377 |
var _this$id, _this$idBase; |
| 378 |
|
| 379 |
this.element = el('div', { |
| 380 |
class: 'widget open' |
| 381 |
}, [el('div', { |
| 382 |
class: 'widget-inside' |
| 383 |
}, [this.form = el('form', { |
| 384 |
class: 'form', |
| 385 |
method: 'post' |
| 386 |
}, [// These hidden form inputs are what most widgets' scripts |
| 387 |
// use to access data about the widget. |
| 388 |
el('input', { |
| 389 |
class: 'widget-id', |
| 390 |
type: 'hidden', |
| 391 |
name: 'widget-id', |
| 392 |
value: (_this$id = this.id) !== null && _this$id !== void 0 ? _this$id : `${this.idBase}-${this.number}` |
| 393 |
}), el('input', { |
| 394 |
class: 'id_base', |
| 395 |
type: 'hidden', |
| 396 |
name: 'id_base', |
| 397 |
value: (_this$idBase = this.idBase) !== null && _this$idBase !== void 0 ? _this$idBase : this.id |
| 398 |
}), el('input', { |
| 399 |
class: 'widget-width', |
| 400 |
type: 'hidden', |
| 401 |
name: 'widget-width', |
| 402 |
value: '250' |
| 403 |
}), el('input', { |
| 404 |
class: 'widget-height', |
| 405 |
type: 'hidden', |
| 406 |
name: 'widget-height', |
| 407 |
value: '200' |
| 408 |
}), el('input', { |
| 409 |
class: 'widget_number', |
| 410 |
type: 'hidden', |
| 411 |
name: 'widget_number', |
| 412 |
value: this.idBase ? this.number.toString() : '' |
| 413 |
}), this.content = el('div', { |
| 414 |
class: 'widget-content' |
| 415 |
}), // Non-multi widgets can be saved via a Save button. |
| 416 |
this.id && el('button', { |
| 417 |
class: 'button is-primary', |
| 418 |
type: 'submit' |
| 419 |
}, (0,external_wp_i18n_namespaceObject.__)('Save'))])])]); |
| 420 |
} |
| 421 |
/** |
| 422 |
* Adds the control's event listeners. |
| 423 |
* |
| 424 |
* @access private |
| 425 |
*/ |
| 426 |
|
| 427 |
|
| 428 |
bindEvents() { |
| 429 |
// Prefer jQuery 'change' event instead of the native 'change' event |
| 430 |
// because many widgets use jQuery's event bus to trigger an update. |
| 431 |
if (window.jQuery) { |
| 432 |
const { |
| 433 |
jQuery: $ |
| 434 |
} = window; |
| 435 |
$(this.form).on('change', null, this.handleFormChange); |
| 436 |
$(this.form).on('input', null, this.handleFormChange); |
| 437 |
$(this.form).on('submit', this.handleFormSubmit); |
| 438 |
} else { |
| 439 |
this.form.addEventListener('change', this.handleFormChange); |
| 440 |
this.form.addEventListener('input', this.handleFormChange); |
| 441 |
this.form.addEventListener('submit', this.handleFormSubmit); |
| 442 |
} |
| 443 |
} |
| 444 |
/** |
| 445 |
* Removes the control's event listeners. |
| 446 |
* |
| 447 |
* @access private |
| 448 |
*/ |
| 449 |
|
| 450 |
|
| 451 |
unbindEvents() { |
| 452 |
if (window.jQuery) { |
| 453 |
const { |
| 454 |
jQuery: $ |
| 455 |
} = window; |
| 456 |
$(this.form).off('change', null, this.handleFormChange); |
| 457 |
$(this.form).off('input', null, this.handleFormChange); |
| 458 |
$(this.form).off('submit', this.handleFormSubmit); |
| 459 |
} else { |
| 460 |
this.form.removeEventListener('change', this.handleFormChange); |
| 461 |
this.form.removeEventListener('input', this.handleFormChange); |
| 462 |
this.form.removeEventListener('submit', this.handleFormSubmit); |
| 463 |
} |
| 464 |
} |
| 465 |
/** |
| 466 |
* Fetches the widget's form HTML from the REST API and loads it into the |
| 467 |
* control's form. |
| 468 |
* |
| 469 |
* @access private |
| 470 |
*/ |
| 471 |
|
| 472 |
|
| 473 |
async loadContent() { |
| 474 |
try { |
| 475 |
if (this.id) { |
| 476 |
const { |
| 477 |
form |
| 478 |
} = await saveWidget(this.id); |
| 479 |
this.content.innerHTML = form; |
| 480 |
} else if (this.idBase) { |
| 481 |
const { |
| 482 |
form, |
| 483 |
preview |
| 484 |
} = await encodeWidget({ |
| 485 |
idBase: this.idBase, |
| 486 |
instance: this.instance, |
| 487 |
number: this.number |
| 488 |
}); |
| 489 |
this.content.innerHTML = form; |
| 490 |
this.hasPreview = !isEmptyHTML(preview); // If we don't have an instance, perform a save right away. This |
| 491 |
// happens when creating a new Legacy Widget block. |
| 492 |
|
| 493 |
if (!this.instance.hash) { |
| 494 |
const { |
| 495 |
instance |
| 496 |
} = await encodeWidget({ |
| 497 |
idBase: this.idBase, |
| 498 |
instance: this.instance, |
| 499 |
number: this.number, |
| 500 |
formData: serializeForm(this.form) |
| 501 |
}); |
| 502 |
this.instance = instance; |
| 503 |
} |
| 504 |
} // Trigger 'widget-added' when widget is ready. This event is what |
| 505 |
// widgets' scripts use to initialize, attach events, etc. The event |
| 506 |
// must be fired using jQuery's event bus as this is what widget |
| 507 |
// scripts expect. If jQuery is not loaded, do nothing - some |
| 508 |
// widgets will still work regardless. |
| 509 |
|
| 510 |
|
| 511 |
if (window.jQuery) { |
| 512 |
const { |
| 513 |
jQuery: $ |
| 514 |
} = window; |
| 515 |
$(document).trigger('widget-added', [$(this.element)]); |
| 516 |
} |
| 517 |
} catch (error) { |
| 518 |
this.onError(error); |
| 519 |
} |
| 520 |
} |
| 521 |
/** |
| 522 |
* Perform a save when a multi widget's form is changed. Non-multi widgets |
| 523 |
* are saved manually. |
| 524 |
* |
| 525 |
* @access private |
| 526 |
*/ |
| 527 |
|
| 528 |
|
| 529 |
handleFormChange() { |
| 530 |
if (this.idBase) { |
| 531 |
this.saveForm(); |
| 532 |
} |
| 533 |
} |
| 534 |
/** |
| 535 |
* Perform a save when the control's form is manually submitted. |
| 536 |
* |
| 537 |
* @access private |
| 538 |
* @param {Event} event |
| 539 |
*/ |
| 540 |
|
| 541 |
|
| 542 |
handleFormSubmit(event) { |
| 543 |
event.preventDefault(); |
| 544 |
this.saveForm(); |
| 545 |
} |
| 546 |
/** |
| 547 |
* Serialize the control's form, send it to the REST API, and update the |
| 548 |
* instance with the encoded instance that the REST API returns. |
| 549 |
* |
| 550 |
* @access private |
| 551 |
*/ |
| 552 |
|
| 553 |
|
| 554 |
async saveForm() { |
| 555 |
const formData = serializeForm(this.form); |
| 556 |
|
| 557 |
try { |
| 558 |
if (this.id) { |
| 559 |
const { |
| 560 |
form |
| 561 |
} = await saveWidget(this.id, formData); |
| 562 |
this.content.innerHTML = form; |
| 563 |
|
| 564 |
if (window.jQuery) { |
| 565 |
const { |
| 566 |
jQuery: $ |
| 567 |
} = window; |
| 568 |
$(document).trigger('widget-updated', [$(this.element)]); |
| 569 |
} |
| 570 |
} else if (this.idBase) { |
| 571 |
const { |
| 572 |
instance, |
| 573 |
preview |
| 574 |
} = await encodeWidget({ |
| 575 |
idBase: this.idBase, |
| 576 |
instance: this.instance, |
| 577 |
number: this.number, |
| 578 |
formData |
| 579 |
}); |
| 580 |
this.instance = instance; |
| 581 |
this.hasPreview = !isEmptyHTML(preview); |
| 582 |
} |
| 583 |
} catch (error) { |
| 584 |
this.onError(error); |
| 585 |
} |
| 586 |
} |
| 587 |
/** |
| 588 |
* The widget's instance object. |
| 589 |
* |
| 590 |
* @access private |
| 591 |
*/ |
| 592 |
|
| 593 |
|
| 594 |
get instance() { |
| 595 |
return this._instance; |
| 596 |
} |
| 597 |
/** |
| 598 |
* The widget's instance object. |
| 599 |
* |
| 600 |
* @access private |
| 601 |
*/ |
| 602 |
|
| 603 |
|
| 604 |
set instance(instance) { |
| 605 |
if (this._instance !== instance) { |
| 606 |
this._instance = instance; |
| 607 |
this.onChangeInstance(instance); |
| 608 |
} |
| 609 |
} |
| 610 |
/** |
| 611 |
* Whether or not the widget can be previewed. |
| 612 |
* |
| 613 |
* @access public |
| 614 |
*/ |
| 615 |
|
| 616 |
|
| 617 |
get hasPreview() { |
| 618 |
return this._hasPreview; |
| 619 |
} |
| 620 |
/** |
| 621 |
* Whether or not the widget can be previewed. |
| 622 |
* |
| 623 |
* @access private |
| 624 |
*/ |
| 625 |
|
| 626 |
|
| 627 |
set hasPreview(hasPreview) { |
| 628 |
if (this._hasPreview !== hasPreview) { |
| 629 |
this._hasPreview = hasPreview; |
| 630 |
this.onChangeHasPreview(hasPreview); |
| 631 |
} |
| 632 |
} |
| 633 |
|
| 634 |
} |
| 635 |
let lastNumber = 0; |
| 636 |
|
| 637 |
function el(tagName) { |
| 638 |
let attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; |
| 639 |
let content = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; |
| 640 |
const element = document.createElement(tagName); |
| 641 |
|
| 642 |
for (const [attribute, value] of Object.entries(attributes)) { |
| 643 |
element.setAttribute(attribute, value); |
| 644 |
} |
| 645 |
|
| 646 |
if (Array.isArray(content)) { |
| 647 |
for (const child of content) { |
| 648 |
if (child) { |
| 649 |
element.appendChild(child); |
| 650 |
} |
| 651 |
} |
| 652 |
} else if (typeof content === 'string') { |
| 653 |
element.innerText = content; |
| 654 |
} |
| 655 |
|
| 656 |
return element; |
| 657 |
} |
| 658 |
|
| 659 |
async function saveWidget(id) { |
| 660 |
let formData = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; |
| 661 |
let widget; |
| 662 |
|
| 663 |
if (formData) { |
| 664 |
widget = await external_wp_apiFetch_default()({ |
| 665 |
path: `/wp/v2/widgets/${id}?context=edit`, |
| 666 |
method: 'PUT', |
| 667 |
data: { |
| 668 |
form_data: formData |
| 669 |
} |
| 670 |
}); |
| 671 |
} else { |
| 672 |
widget = await external_wp_apiFetch_default()({ |
| 673 |
path: `/wp/v2/widgets/${id}?context=edit`, |
| 674 |
method: 'GET' |
| 675 |
}); |
| 676 |
} |
| 677 |
|
| 678 |
return { |
| 679 |
form: widget.rendered_form |
| 680 |
}; |
| 681 |
} |
| 682 |
|
| 683 |
async function encodeWidget(_ref2) { |
| 684 |
let { |
| 685 |
idBase, |
| 686 |
instance, |
| 687 |
number, |
| 688 |
formData = null |
| 689 |
} = _ref2; |
| 690 |
const response = await external_wp_apiFetch_default()({ |
| 691 |
path: `/wp/v2/widget-types/${idBase}/encode`, |
| 692 |
method: 'POST', |
| 693 |
data: { |
| 694 |
instance, |
| 695 |
number, |
| 696 |
form_data: formData |
| 697 |
} |
| 698 |
}); |
| 699 |
return { |
| 700 |
instance: response.instance, |
| 701 |
form: response.form, |
| 702 |
preview: response.preview |
| 703 |
}; |
| 704 |
} |
| 705 |
|
| 706 |
function isEmptyHTML(html) { |
| 707 |
const element = document.createElement('div'); |
| 708 |
element.innerHTML = html; |
| 709 |
return isEmptyNode(element); |
| 710 |
} |
| 711 |
|
| 712 |
function isEmptyNode(node) { |
| 713 |
switch (node.nodeType) { |
| 714 |
case node.TEXT_NODE: |
| 715 |
// Text nodes are empty if it's entirely whitespace. |
| 716 |
return node.nodeValue.trim() === ''; |
| 717 |
|
| 718 |
case node.ELEMENT_NODE: |
| 719 |
// Elements that are "embedded content" are not empty. |
| 720 |
// https://dev.w3.org/html5/spec-LC/content-models.html#embedded-content-0 |
| 721 |
if (['AUDIO', 'CANVAS', 'EMBED', 'IFRAME', 'IMG', 'MATH', 'OBJECT', 'SVG', 'VIDEO'].includes(node.tagName)) { |
| 722 |
return false; |
| 723 |
} // Elements with no children are empty. |
| 724 |
|
| 725 |
|
| 726 |
if (!node.hasChildNodes()) { |
| 727 |
return true; |
| 728 |
} // Elements with children are empty if all their children are empty. |
| 729 |
|
| 730 |
|
| 731 |
return Array.from(node.childNodes).every(isEmptyNode); |
| 732 |
|
| 733 |
default: |
| 734 |
return true; |
| 735 |
} |
| 736 |
} |
| 737 |
|
| 738 |
function serializeForm(form) { |
| 739 |
return new window.URLSearchParams(Array.from(new window.FormData(form))).toString(); |
| 740 |
} |
| 741 |
|
| 742 |
;// CONCATENATED MODULE: ./packages/widgets/build-module/blocks/legacy-widget/edit/form.js |
| 743 |
|
| 744 |
|
| 745 |
/** |
| 746 |
* External dependencies |
| 747 |
*/ |
| 748 |
|
| 749 |
/** |
| 750 |
* WordPress dependencies |
| 751 |
*/ |
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
/** |
| 760 |
* Internal dependencies |
| 761 |
*/ |
| 762 |
|
| 763 |
|
| 764 |
function Form(_ref) { |
| 765 |
let { |
| 766 |
title, |
| 767 |
isVisible, |
| 768 |
id, |
| 769 |
idBase, |
| 770 |
instance, |
| 771 |
isWide, |
| 772 |
onChangeInstance, |
| 773 |
onChangeHasPreview |
| 774 |
} = _ref; |
| 775 |
const ref = (0,external_wp_element_namespaceObject.useRef)(); |
| 776 |
const isMediumLargeViewport = (0,external_wp_compose_namespaceObject.useViewportMatch)('small'); // We only want to remount the control when the instance changes |
| 777 |
// *externally*. For example, if the user performs an undo. To do this, we |
| 778 |
// keep track of changes made to instance by the control itself and then |
| 779 |
// ignore those. |
| 780 |
|
| 781 |
const outgoingInstances = (0,external_wp_element_namespaceObject.useRef)(new Set()); |
| 782 |
const incomingInstances = (0,external_wp_element_namespaceObject.useRef)(new Set()); |
| 783 |
const { |
| 784 |
createNotice |
| 785 |
} = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_notices_namespaceObject.store); |
| 786 |
(0,external_wp_element_namespaceObject.useEffect)(() => { |
| 787 |
if (incomingInstances.current.has(instance)) { |
| 788 |
incomingInstances.current.delete(instance); |
| 789 |
return; |
| 790 |
} |
| 791 |
|
| 792 |
const control = new Control({ |
| 793 |
id, |
| 794 |
idBase, |
| 795 |
instance, |
| 796 |
|
| 797 |
onChangeInstance(nextInstance) { |
| 798 |
outgoingInstances.current.add(instance); |
| 799 |
incomingInstances.current.add(nextInstance); |
| 800 |
onChangeInstance(nextInstance); |
| 801 |
}, |
| 802 |
|
| 803 |
onChangeHasPreview, |
| 804 |
|
| 805 |
onError(error) { |
| 806 |
window.console.error(error); |
| 807 |
createNotice('error', (0,external_wp_i18n_namespaceObject.sprintf)( |
| 808 |
/* translators: %s: the name of the affected block. */ |
| 809 |
(0,external_wp_i18n_namespaceObject.__)('The "%s" block was affected by errors and may not function properly. Check the developer tools for more details.'), idBase || id)); |
| 810 |
} |
| 811 |
|
| 812 |
}); |
| 813 |
ref.current.appendChild(control.element); |
| 814 |
return () => { |
| 815 |
if (outgoingInstances.current.has(instance)) { |
| 816 |
outgoingInstances.current.delete(instance); |
| 817 |
return; |
| 818 |
} |
| 819 |
|
| 820 |
control.destroy(); |
| 821 |
}; |
| 822 |
}, [id, idBase, instance, onChangeInstance, onChangeHasPreview, isMediumLargeViewport]); |
| 823 |
|
| 824 |
if (isWide && isMediumLargeViewport) { |
| 825 |
return (0,external_wp_element_namespaceObject.createElement)("div", { |
| 826 |
className: classnames_default()({ |
| 827 |
'wp-block-legacy-widget__container': isVisible |
| 828 |
}) |
| 829 |
}, isVisible && (0,external_wp_element_namespaceObject.createElement)("h3", { |
| 830 |
className: "wp-block-legacy-widget__edit-form-title" |
| 831 |
}, title), (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Popover, { |
| 832 |
focusOnMount: false, |
| 833 |
placement: "right", |
| 834 |
offset: 32, |
| 835 |
resize: false, |
| 836 |
flip: false, |
| 837 |
shift: true |
| 838 |
}, (0,external_wp_element_namespaceObject.createElement)("div", { |
| 839 |
ref: ref, |
| 840 |
className: "wp-block-legacy-widget__edit-form", |
| 841 |
hidden: !isVisible |
| 842 |
}))); |
| 843 |
} |
| 844 |
|
| 845 |
return (0,external_wp_element_namespaceObject.createElement)("div", { |
| 846 |
ref: ref, |
| 847 |
className: "wp-block-legacy-widget__edit-form", |
| 848 |
hidden: !isVisible |
| 849 |
}, (0,external_wp_element_namespaceObject.createElement)("h3", { |
| 850 |
className: "wp-block-legacy-widget__edit-form-title" |
| 851 |
}, title)); |
| 852 |
} |
| 853 |
|
| 854 |
;// CONCATENATED MODULE: ./packages/widgets/build-module/blocks/legacy-widget/edit/preview.js |
| 855 |
|
| 856 |
|
| 857 |
/** |
| 858 |
* External dependencies |
| 859 |
*/ |
| 860 |
|
| 861 |
/** |
| 862 |
* WordPress dependencies |
| 863 |
*/ |
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
function Preview(_ref) { |
| 871 |
let { |
| 872 |
idBase, |
| 873 |
instance, |
| 874 |
isVisible |
| 875 |
} = _ref; |
| 876 |
const [isLoaded, setIsLoaded] = (0,external_wp_element_namespaceObject.useState)(false); |
| 877 |
const [srcDoc, setSrcDoc] = (0,external_wp_element_namespaceObject.useState)(''); |
| 878 |
(0,external_wp_element_namespaceObject.useEffect)(() => { |
| 879 |
const abortController = typeof window.AbortController === 'undefined' ? undefined : new window.AbortController(); |
| 880 |
|
| 881 |
async function fetchPreviewHTML() { |
| 882 |
const restRoute = `/wp/v2/widget-types/${idBase}/render`; |
| 883 |
return await external_wp_apiFetch_default()({ |
| 884 |
path: restRoute, |
| 885 |
method: 'POST', |
| 886 |
signal: abortController === null || abortController === void 0 ? void 0 : abortController.signal, |
| 887 |
data: instance ? { |
| 888 |
instance |
| 889 |
} : {} |
| 890 |
}); |
| 891 |
} |
| 892 |
|
| 893 |
fetchPreviewHTML().then(response => { |
| 894 |
setSrcDoc(response.preview); |
| 895 |
}).catch(error => { |
| 896 |
if ('AbortError' === error.name) { |
| 897 |
// We don't want to log aborted requests. |
| 898 |
return; |
| 899 |
} |
| 900 |
|
| 901 |
throw error; |
| 902 |
}); |
| 903 |
return () => abortController === null || abortController === void 0 ? void 0 : abortController.abort(); |
| 904 |
}, [idBase, instance]); // Resize the iframe on either the load event, or when the iframe becomes visible. |
| 905 |
|
| 906 |
const ref = (0,external_wp_compose_namespaceObject.useRefEffect)(iframe => { |
| 907 |
// Only set height if the iframe is loaded, |
| 908 |
// or it will grow to an unexpected large height in Safari if it's hidden initially. |
| 909 |
if (!isLoaded) { |
| 910 |
return; |
| 911 |
} // If the preview frame has another origin then this won't work. |
| 912 |
// One possible solution is to add custom script to call `postMessage` in the preview frame. |
| 913 |
// Or, better yet, we migrate away from iframe. |
| 914 |
|
| 915 |
|
| 916 |
function setHeight() { |
| 917 |
var _iframe$contentDocume, _iframe$contentDocume2, _iframe$contentDocume3, _iframe$contentDocume4; |
| 918 |
|
| 919 |
// Pick the maximum of these two values to account for margin collapsing. |
| 920 |
const height = Math.max((_iframe$contentDocume = (_iframe$contentDocume2 = iframe.contentDocument.documentElement) === null || _iframe$contentDocume2 === void 0 ? void 0 : _iframe$contentDocume2.offsetHeight) !== null && _iframe$contentDocume !== void 0 ? _iframe$contentDocume : 0, (_iframe$contentDocume3 = (_iframe$contentDocume4 = iframe.contentDocument.body) === null || _iframe$contentDocume4 === void 0 ? void 0 : _iframe$contentDocume4.offsetHeight) !== null && _iframe$contentDocume3 !== void 0 ? _iframe$contentDocume3 : 0); // Fallback to a height of 100px if the height cannot be determined. |
| 921 |
// This ensures the block is still selectable. 100px should hopefully |
| 922 |
// be not so big that it's annoying, and not so small that nothing |
| 923 |
// can be seen. |
| 924 |
|
| 925 |
iframe.style.height = `${height !== 0 ? height : 100}px`; |
| 926 |
} |
| 927 |
|
| 928 |
const { |
| 929 |
IntersectionObserver |
| 930 |
} = iframe.ownerDocument.defaultView; // Observe for intersections that might cause a change in the height of |
| 931 |
// the iframe, e.g. a Widget Area becoming expanded. |
| 932 |
|
| 933 |
const intersectionObserver = new IntersectionObserver(_ref2 => { |
| 934 |
let [entry] = _ref2; |
| 935 |
|
| 936 |
if (entry.isIntersecting) { |
| 937 |
setHeight(); |
| 938 |
} |
| 939 |
}, { |
| 940 |
threshold: 1 |
| 941 |
}); |
| 942 |
intersectionObserver.observe(iframe); |
| 943 |
iframe.addEventListener('load', setHeight); |
| 944 |
return () => { |
| 945 |
intersectionObserver.disconnect(); |
| 946 |
iframe.removeEventListener('load', setHeight); |
| 947 |
}; |
| 948 |
}, [isLoaded]); |
| 949 |
return (0,external_wp_element_namespaceObject.createElement)(external_wp_element_namespaceObject.Fragment, null, isVisible && !isLoaded && (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Placeholder, null, (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Spinner, null)), (0,external_wp_element_namespaceObject.createElement)("div", { |
| 950 |
className: classnames_default()('wp-block-legacy-widget__edit-preview', { |
| 951 |
'is-offscreen': !isVisible || !isLoaded |
| 952 |
}) |
| 953 |
}, (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Disabled, null, (0,external_wp_element_namespaceObject.createElement)("iframe", { |
| 954 |
ref: ref, |
| 955 |
className: "wp-block-legacy-widget__edit-preview-iframe", |
| 956 |
tabIndex: "-1", |
| 957 |
title: (0,external_wp_i18n_namespaceObject.__)('Legacy Widget Preview'), |
| 958 |
srcDoc: srcDoc, |
| 959 |
onLoad: event => { |
| 960 |
// To hide the scrollbars of the preview frame for some edge cases, |
| 961 |
// such as negative margins in the Gallery Legacy Widget. |
| 962 |
// It can't be scrolled anyway. |
| 963 |
// TODO: Ideally, this should be fixed in core. |
| 964 |
event.target.contentDocument.body.style.overflow = 'hidden'; |
| 965 |
setIsLoaded(true); |
| 966 |
}, |
| 967 |
height: 100 |
| 968 |
})))); |
| 969 |
} |
| 970 |
|
| 971 |
;// CONCATENATED MODULE: ./packages/widgets/build-module/blocks/legacy-widget/edit/no-preview.js |
| 972 |
|
| 973 |
|
| 974 |
/** |
| 975 |
* WordPress dependencies |
| 976 |
*/ |
| 977 |
|
| 978 |
function NoPreview(_ref) { |
| 979 |
let { |
| 980 |
name |
| 981 |
} = _ref; |
| 982 |
return (0,external_wp_element_namespaceObject.createElement)("div", { |
| 983 |
className: "wp-block-legacy-widget__edit-no-preview" |
| 984 |
}, name && (0,external_wp_element_namespaceObject.createElement)("h3", null, name), (0,external_wp_element_namespaceObject.createElement)("p", null, (0,external_wp_i18n_namespaceObject.__)('No preview available.'))); |
| 985 |
} |
| 986 |
|
| 987 |
;// CONCATENATED MODULE: ./packages/widgets/build-module/blocks/legacy-widget/edit/convert-to-blocks-button.js |
| 988 |
|
| 989 |
|
| 990 |
/** |
| 991 |
* WordPress dependencies |
| 992 |
*/ |
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
function ConvertToBlocksButton(_ref) { |
| 999 |
let { |
| 1000 |
clientId, |
| 1001 |
rawInstance |
| 1002 |
} = _ref; |
| 1003 |
const { |
| 1004 |
replaceBlocks |
| 1005 |
} = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_blockEditor_namespaceObject.store); |
| 1006 |
return (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.ToolbarButton, { |
| 1007 |
onClick: () => { |
| 1008 |
if (rawInstance.title) { |
| 1009 |
replaceBlocks(clientId, [(0,external_wp_blocks_namespaceObject.createBlock)('core/heading', { |
| 1010 |
content: rawInstance.title |
| 1011 |
}), ...(0,external_wp_blocks_namespaceObject.rawHandler)({ |
| 1012 |
HTML: rawInstance.text |
| 1013 |
})]); |
| 1014 |
} else { |
| 1015 |
replaceBlocks(clientId, (0,external_wp_blocks_namespaceObject.rawHandler)({ |
| 1016 |
HTML: rawInstance.text |
| 1017 |
})); |
| 1018 |
} |
| 1019 |
} |
| 1020 |
}, (0,external_wp_i18n_namespaceObject.__)('Convert to blocks')); |
| 1021 |
} |
| 1022 |
|
| 1023 |
;// CONCATENATED MODULE: ./packages/widgets/build-module/blocks/legacy-widget/edit/index.js |
| 1024 |
|
| 1025 |
|
| 1026 |
/** |
| 1027 |
* External dependencies |
| 1028 |
*/ |
| 1029 |
|
| 1030 |
/** |
| 1031 |
* WordPress dependencies |
| 1032 |
*/ |
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
/** |
| 1042 |
* Internal dependencies |
| 1043 |
*/ |
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
function Edit(props) { |
| 1052 |
const { |
| 1053 |
id, |
| 1054 |
idBase |
| 1055 |
} = props.attributes; |
| 1056 |
const { |
| 1057 |
isWide = false |
| 1058 |
} = props; |
| 1059 |
const blockProps = (0,external_wp_blockEditor_namespaceObject.useBlockProps)({ |
| 1060 |
className: classnames_default()({ |
| 1061 |
'is-wide-widget': isWide |
| 1062 |
}) |
| 1063 |
}); |
| 1064 |
return (0,external_wp_element_namespaceObject.createElement)("div", blockProps, !id && !idBase ? (0,external_wp_element_namespaceObject.createElement)(Empty, props) : (0,external_wp_element_namespaceObject.createElement)(NotEmpty, props)); |
| 1065 |
} |
| 1066 |
|
| 1067 |
function Empty(_ref) { |
| 1068 |
let { |
| 1069 |
attributes: { |
| 1070 |
id, |
| 1071 |
idBase |
| 1072 |
}, |
| 1073 |
setAttributes |
| 1074 |
} = _ref; |
| 1075 |
return (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Placeholder, { |
| 1076 |
icon: (0,external_wp_element_namespaceObject.createElement)(external_wp_blockEditor_namespaceObject.BlockIcon, { |
| 1077 |
icon: library_brush |
| 1078 |
}), |
| 1079 |
label: (0,external_wp_i18n_namespaceObject.__)('Legacy Widget') |
| 1080 |
}, (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Flex, null, (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.FlexBlock, null, (0,external_wp_element_namespaceObject.createElement)(WidgetTypeSelector, { |
| 1081 |
selectedId: id !== null && id !== void 0 ? id : idBase, |
| 1082 |
onSelect: _ref2 => { |
| 1083 |
let { |
| 1084 |
selectedId, |
| 1085 |
isMulti |
| 1086 |
} = _ref2; |
| 1087 |
|
| 1088 |
if (!selectedId) { |
| 1089 |
setAttributes({ |
| 1090 |
id: null, |
| 1091 |
idBase: null, |
| 1092 |
instance: null |
| 1093 |
}); |
| 1094 |
} else if (isMulti) { |
| 1095 |
setAttributes({ |
| 1096 |
id: null, |
| 1097 |
idBase: selectedId, |
| 1098 |
instance: {} |
| 1099 |
}); |
| 1100 |
} else { |
| 1101 |
setAttributes({ |
| 1102 |
id: selectedId, |
| 1103 |
idBase: null, |
| 1104 |
instance: null |
| 1105 |
}); |
| 1106 |
} |
| 1107 |
} |
| 1108 |
})))); |
| 1109 |
} |
| 1110 |
|
| 1111 |
function NotEmpty(_ref3) { |
| 1112 |
let { |
| 1113 |
attributes: { |
| 1114 |
id, |
| 1115 |
idBase, |
| 1116 |
instance |
| 1117 |
}, |
| 1118 |
setAttributes, |
| 1119 |
clientId, |
| 1120 |
isSelected, |
| 1121 |
isWide = false |
| 1122 |
} = _ref3; |
| 1123 |
const [hasPreview, setHasPreview] = (0,external_wp_element_namespaceObject.useState)(null); |
| 1124 |
const widgetTypeId = id !== null && id !== void 0 ? id : idBase; |
| 1125 |
const { |
| 1126 |
record: widgetType, |
| 1127 |
hasResolved: hasResolvedWidgetType |
| 1128 |
} = (0,external_wp_coreData_namespaceObject.useEntityRecord)('root', 'widgetType', widgetTypeId); |
| 1129 |
const isNavigationMode = (0,external_wp_data_namespaceObject.useSelect)(select => select(external_wp_blockEditor_namespaceObject.store).isNavigationMode(), []); |
| 1130 |
const setInstance = (0,external_wp_element_namespaceObject.useCallback)(nextInstance => { |
| 1131 |
setAttributes({ |
| 1132 |
instance: nextInstance |
| 1133 |
}); |
| 1134 |
}, []); |
| 1135 |
|
| 1136 |
if (!widgetType && hasResolvedWidgetType) { |
| 1137 |
return (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Placeholder, { |
| 1138 |
icon: (0,external_wp_element_namespaceObject.createElement)(external_wp_blockEditor_namespaceObject.BlockIcon, { |
| 1139 |
icon: library_brush |
| 1140 |
}), |
| 1141 |
label: (0,external_wp_i18n_namespaceObject.__)('Legacy Widget') |
| 1142 |
}, (0,external_wp_i18n_namespaceObject.__)('Widget is missing.')); |
| 1143 |
} |
| 1144 |
|
| 1145 |
if (!hasResolvedWidgetType) { |
| 1146 |
return (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Placeholder, null, (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Spinner, null)); |
| 1147 |
} |
| 1148 |
|
| 1149 |
const mode = idBase && (isNavigationMode || !isSelected) ? 'preview' : 'edit'; |
| 1150 |
return (0,external_wp_element_namespaceObject.createElement)(external_wp_element_namespaceObject.Fragment, null, idBase === 'text' && (0,external_wp_element_namespaceObject.createElement)(external_wp_blockEditor_namespaceObject.BlockControls, { |
| 1151 |
group: "other" |
| 1152 |
}, (0,external_wp_element_namespaceObject.createElement)(ConvertToBlocksButton, { |
| 1153 |
clientId: clientId, |
| 1154 |
rawInstance: instance.raw |
| 1155 |
})), (0,external_wp_element_namespaceObject.createElement)(external_wp_blockEditor_namespaceObject.InspectorControls, null, (0,external_wp_element_namespaceObject.createElement)(InspectorCard, { |
| 1156 |
name: widgetType.name, |
| 1157 |
description: widgetType.description |
| 1158 |
})), (0,external_wp_element_namespaceObject.createElement)(Form, { |
| 1159 |
title: widgetType.name, |
| 1160 |
isVisible: mode === 'edit', |
| 1161 |
id: id, |
| 1162 |
idBase: idBase, |
| 1163 |
instance: instance, |
| 1164 |
isWide: isWide, |
| 1165 |
onChangeInstance: setInstance, |
| 1166 |
onChangeHasPreview: setHasPreview |
| 1167 |
}), idBase && (0,external_wp_element_namespaceObject.createElement)(external_wp_element_namespaceObject.Fragment, null, hasPreview === null && mode === 'preview' && (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Placeholder, null, (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Spinner, null)), hasPreview === true && (0,external_wp_element_namespaceObject.createElement)(Preview, { |
| 1168 |
idBase: idBase, |
| 1169 |
instance: instance, |
| 1170 |
isVisible: mode === 'preview' |
| 1171 |
}), hasPreview === false && mode === 'preview' && (0,external_wp_element_namespaceObject.createElement)(NoPreview, { |
| 1172 |
name: widgetType.name |
| 1173 |
}))); |
| 1174 |
} |
| 1175 |
|
| 1176 |
;// CONCATENATED MODULE: ./packages/widgets/build-module/blocks/legacy-widget/transforms.js |
| 1177 |
/** |
| 1178 |
* WordPress dependencies |
| 1179 |
*/ |
| 1180 |
|
| 1181 |
const legacyWidgetTransforms = [{ |
| 1182 |
block: 'core/calendar', |
| 1183 |
widget: 'calendar' |
| 1184 |
}, { |
| 1185 |
block: 'core/search', |
| 1186 |
widget: 'search' |
| 1187 |
}, { |
| 1188 |
block: 'core/html', |
| 1189 |
widget: 'custom_html', |
| 1190 |
transform: _ref => { |
| 1191 |
let { |
| 1192 |
content |
| 1193 |
} = _ref; |
| 1194 |
return { |
| 1195 |
content |
| 1196 |
}; |
| 1197 |
} |
| 1198 |
}, { |
| 1199 |
block: 'core/archives', |
| 1200 |
widget: 'archives', |
| 1201 |
transform: _ref2 => { |
| 1202 |
let { |
| 1203 |
count, |
| 1204 |
dropdown |
| 1205 |
} = _ref2; |
| 1206 |
return { |
| 1207 |
displayAsDropdown: !!dropdown, |
| 1208 |
showPostCounts: !!count |
| 1209 |
}; |
| 1210 |
} |
| 1211 |
}, { |
| 1212 |
block: 'core/latest-posts', |
| 1213 |
widget: 'recent-posts', |
| 1214 |
transform: _ref3 => { |
| 1215 |
let { |
| 1216 |
show_date: displayPostDate, |
| 1217 |
number |
| 1218 |
} = _ref3; |
| 1219 |
return { |
| 1220 |
displayPostDate: !!displayPostDate, |
| 1221 |
postsToShow: number |
| 1222 |
}; |
| 1223 |
} |
| 1224 |
}, { |
| 1225 |
block: 'core/latest-comments', |
| 1226 |
widget: 'recent-comments', |
| 1227 |
transform: _ref4 => { |
| 1228 |
let { |
| 1229 |
number |
| 1230 |
} = _ref4; |
| 1231 |
return { |
| 1232 |
commentsToShow: number |
| 1233 |
}; |
| 1234 |
} |
| 1235 |
}, { |
| 1236 |
block: 'core/tag-cloud', |
| 1237 |
widget: 'tag_cloud', |
| 1238 |
transform: _ref5 => { |
| 1239 |
let { |
| 1240 |
taxonomy, |
| 1241 |
count |
| 1242 |
} = _ref5; |
| 1243 |
return { |
| 1244 |
showTagCounts: !!count, |
| 1245 |
taxonomy |
| 1246 |
}; |
| 1247 |
} |
| 1248 |
}, { |
| 1249 |
block: 'core/categories', |
| 1250 |
widget: 'categories', |
| 1251 |
transform: _ref6 => { |
| 1252 |
let { |
| 1253 |
count, |
| 1254 |
dropdown, |
| 1255 |
hierarchical |
| 1256 |
} = _ref6; |
| 1257 |
return { |
| 1258 |
displayAsDropdown: !!dropdown, |
| 1259 |
showPostCounts: !!count, |
| 1260 |
showHierarchy: !!hierarchical |
| 1261 |
}; |
| 1262 |
} |
| 1263 |
}, { |
| 1264 |
block: 'core/audio', |
| 1265 |
widget: 'media_audio', |
| 1266 |
transform: _ref7 => { |
| 1267 |
let { |
| 1268 |
url, |
| 1269 |
preload, |
| 1270 |
loop, |
| 1271 |
attachment_id: id |
| 1272 |
} = _ref7; |
| 1273 |
return { |
| 1274 |
src: url, |
| 1275 |
id, |
| 1276 |
preload, |
| 1277 |
loop |
| 1278 |
}; |
| 1279 |
} |
| 1280 |
}, { |
| 1281 |
block: 'core/video', |
| 1282 |
widget: 'media_video', |
| 1283 |
transform: _ref8 => { |
| 1284 |
let { |
| 1285 |
url, |
| 1286 |
preload, |
| 1287 |
loop, |
| 1288 |
attachment_id: id |
| 1289 |
} = _ref8; |
| 1290 |
return { |
| 1291 |
src: url, |
| 1292 |
id, |
| 1293 |
preload, |
| 1294 |
loop |
| 1295 |
}; |
| 1296 |
} |
| 1297 |
}, { |
| 1298 |
block: 'core/image', |
| 1299 |
widget: 'media_image', |
| 1300 |
transform: _ref9 => { |
| 1301 |
let { |
| 1302 |
alt, |
| 1303 |
attachment_id: id, |
| 1304 |
caption, |
| 1305 |
height, |
| 1306 |
link_classes: linkClass, |
| 1307 |
link_rel: rel, |
| 1308 |
link_target_blank: targetBlack, |
| 1309 |
link_type: linkDestination, |
| 1310 |
link_url: link, |
| 1311 |
size: sizeSlug, |
| 1312 |
url, |
| 1313 |
width |
| 1314 |
} = _ref9; |
| 1315 |
return { |
| 1316 |
alt, |
| 1317 |
caption, |
| 1318 |
height, |
| 1319 |
id, |
| 1320 |
link, |
| 1321 |
linkClass, |
| 1322 |
linkDestination, |
| 1323 |
linkTarget: targetBlack ? '_blank' : undefined, |
| 1324 |
rel, |
| 1325 |
sizeSlug, |
| 1326 |
url, |
| 1327 |
width |
| 1328 |
}; |
| 1329 |
} |
| 1330 |
}, { |
| 1331 |
block: 'core/gallery', |
| 1332 |
widget: 'media_gallery', |
| 1333 |
transform: _ref10 => { |
| 1334 |
let { |
| 1335 |
ids, |
| 1336 |
link_type: linkTo, |
| 1337 |
size, |
| 1338 |
number |
| 1339 |
} = _ref10; |
| 1340 |
return { |
| 1341 |
ids, |
| 1342 |
columns: number, |
| 1343 |
linkTo, |
| 1344 |
sizeSlug: size, |
| 1345 |
images: ids.map(id => ({ |
| 1346 |
id |
| 1347 |
})) |
| 1348 |
}; |
| 1349 |
} |
| 1350 |
}, { |
| 1351 |
block: 'core/rss', |
| 1352 |
widget: 'rss', |
| 1353 |
transform: _ref11 => { |
| 1354 |
let { |
| 1355 |
url, |
| 1356 |
show_author: displayAuthor, |
| 1357 |
show_date: displayDate, |
| 1358 |
show_summary: displayExcerpt, |
| 1359 |
items |
| 1360 |
} = _ref11; |
| 1361 |
return { |
| 1362 |
feedURL: url, |
| 1363 |
displayAuthor: !!displayAuthor, |
| 1364 |
displayDate: !!displayDate, |
| 1365 |
displayExcerpt: !!displayExcerpt, |
| 1366 |
itemsToShow: items |
| 1367 |
}; |
| 1368 |
} |
| 1369 |
}].map(_ref12 => { |
| 1370 |
let { |
| 1371 |
block, |
| 1372 |
widget, |
| 1373 |
transform |
| 1374 |
} = _ref12; |
| 1375 |
return { |
| 1376 |
type: 'block', |
| 1377 |
blocks: [block], |
| 1378 |
isMatch: _ref13 => { |
| 1379 |
let { |
| 1380 |
idBase, |
| 1381 |
instance |
| 1382 |
} = _ref13; |
| 1383 |
return idBase === widget && !!(instance !== null && instance !== void 0 && instance.raw); |
| 1384 |
}, |
| 1385 |
transform: _ref14 => { |
| 1386 |
var _instance$raw; |
| 1387 |
|
| 1388 |
let { |
| 1389 |
instance |
| 1390 |
} = _ref14; |
| 1391 |
const transformedBlock = (0,external_wp_blocks_namespaceObject.createBlock)(block, transform ? transform(instance.raw) : undefined); |
| 1392 |
|
| 1393 |
if (!((_instance$raw = instance.raw) !== null && _instance$raw !== void 0 && _instance$raw.title)) { |
| 1394 |
return transformedBlock; |
| 1395 |
} |
| 1396 |
|
| 1397 |
return [(0,external_wp_blocks_namespaceObject.createBlock)('core/heading', { |
| 1398 |
content: instance.raw.title |
| 1399 |
}), transformedBlock]; |
| 1400 |
} |
| 1401 |
}; |
| 1402 |
}); |
| 1403 |
const transforms = { |
| 1404 |
to: legacyWidgetTransforms |
| 1405 |
}; |
| 1406 |
/* harmony default export */ var legacy_widget_transforms = (transforms); |
| 1407 |
|
| 1408 |
;// CONCATENATED MODULE: ./packages/widgets/build-module/blocks/legacy-widget/index.js |
| 1409 |
/** |
| 1410 |
* WordPress dependencies |
| 1411 |
*/ |
| 1412 |
|
| 1413 |
/** |
| 1414 |
* Internal dependencies |
| 1415 |
*/ |
| 1416 |
|
| 1417 |
const metadata = { |
| 1418 |
apiVersion: 2, |
| 1419 |
name: "core/legacy-widget", |
| 1420 |
title: "Legacy Widget", |
| 1421 |
category: "widgets", |
| 1422 |
description: "Display a legacy widget.", |
| 1423 |
textdomain: "default", |
| 1424 |
attributes: { |
| 1425 |
id: { |
| 1426 |
type: "string", |
| 1427 |
"default": null |
| 1428 |
}, |
| 1429 |
idBase: { |
| 1430 |
type: "string", |
| 1431 |
"default": null |
| 1432 |
}, |
| 1433 |
instance: { |
| 1434 |
type: "object", |
| 1435 |
"default": null |
| 1436 |
} |
| 1437 |
}, |
| 1438 |
supports: { |
| 1439 |
html: false, |
| 1440 |
customClassName: false, |
| 1441 |
reusable: false |
| 1442 |
}, |
| 1443 |
editorStyle: "wp-block-legacy-widget-editor" |
| 1444 |
}; |
| 1445 |
|
| 1446 |
|
| 1447 |
const { |
| 1448 |
name: legacy_widget_name |
| 1449 |
} = metadata; |
| 1450 |
|
| 1451 |
const settings = { |
| 1452 |
icon: library_widget, |
| 1453 |
edit: Edit, |
| 1454 |
transforms: legacy_widget_transforms |
| 1455 |
}; |
| 1456 |
|
| 1457 |
;// CONCATENATED MODULE: ./packages/icons/build-module/library/group.js |
| 1458 |
|
| 1459 |
|
| 1460 |
/** |
| 1461 |
* WordPress dependencies |
| 1462 |
*/ |
| 1463 |
|
| 1464 |
const group = (0,external_wp_element_namespaceObject.createElement)(external_wp_primitives_namespaceObject.SVG, { |
| 1465 |
viewBox: "0 0 24 24", |
| 1466 |
xmlns: "http://www.w3.org/2000/svg" |
| 1467 |
}, (0,external_wp_element_namespaceObject.createElement)(external_wp_primitives_namespaceObject.Path, { |
| 1468 |
d: "M18 4h-7c-1.1 0-2 .9-2 2v3H6c-1.1 0-2 .9-2 2v7c0 1.1.9 2 2 2h7c1.1 0 2-.9 2-2v-3h3c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm-4.5 14c0 .3-.2.5-.5.5H6c-.3 0-.5-.2-.5-.5v-7c0-.3.2-.5.5-.5h3V13c0 1.1.9 2 2 2h2.5v3zm0-4.5H11c-.3 0-.5-.2-.5-.5v-2.5H13c.3 0 .5.2.5.5v2.5zm5-.5c0 .3-.2.5-.5.5h-3V11c0-1.1-.9-2-2-2h-2.5V6c0-.3.2-.5.5-.5h7c.3 0 .5.2.5.5v7z" |
| 1469 |
})); |
| 1470 |
/* harmony default export */ var library_group = (group); |
| 1471 |
|
| 1472 |
;// CONCATENATED MODULE: ./packages/widgets/build-module/blocks/widget-group/edit.js |
| 1473 |
|
| 1474 |
|
| 1475 |
/** |
| 1476 |
* WordPress dependencies |
| 1477 |
*/ |
| 1478 |
|
| 1479 |
|
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
function edit_Edit(props) { |
| 1484 |
const { |
| 1485 |
clientId |
| 1486 |
} = props; |
| 1487 |
const { |
| 1488 |
innerBlocks |
| 1489 |
} = (0,external_wp_data_namespaceObject.useSelect)(select => select(external_wp_blockEditor_namespaceObject.store).getBlock(clientId), [clientId]); |
| 1490 |
return (0,external_wp_element_namespaceObject.createElement)("div", (0,external_wp_blockEditor_namespaceObject.useBlockProps)({ |
| 1491 |
className: 'widget' |
| 1492 |
}), innerBlocks.length === 0 ? (0,external_wp_element_namespaceObject.createElement)(PlaceholderContent, props) : (0,external_wp_element_namespaceObject.createElement)(PreviewContent, props)); |
| 1493 |
} |
| 1494 |
|
| 1495 |
function PlaceholderContent(_ref) { |
| 1496 |
let { |
| 1497 |
clientId |
| 1498 |
} = _ref; |
| 1499 |
return (0,external_wp_element_namespaceObject.createElement)(external_wp_element_namespaceObject.Fragment, null, (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Placeholder, { |
| 1500 |
className: "wp-block-widget-group__placeholder", |
| 1501 |
icon: (0,external_wp_element_namespaceObject.createElement)(external_wp_blockEditor_namespaceObject.BlockIcon, { |
| 1502 |
icon: library_group |
| 1503 |
}), |
| 1504 |
label: (0,external_wp_i18n_namespaceObject.__)('Widget Group') |
| 1505 |
}, (0,external_wp_element_namespaceObject.createElement)(external_wp_blockEditor_namespaceObject.ButtonBlockAppender, { |
| 1506 |
rootClientId: clientId |
| 1507 |
})), (0,external_wp_element_namespaceObject.createElement)(external_wp_blockEditor_namespaceObject.InnerBlocks, { |
| 1508 |
renderAppender: false |
| 1509 |
})); |
| 1510 |
} |
| 1511 |
|
| 1512 |
function PreviewContent(_ref2) { |
| 1513 |
var _attributes$title; |
| 1514 |
|
| 1515 |
let { |
| 1516 |
attributes, |
| 1517 |
setAttributes |
| 1518 |
} = _ref2; |
| 1519 |
return (0,external_wp_element_namespaceObject.createElement)(external_wp_element_namespaceObject.Fragment, null, (0,external_wp_element_namespaceObject.createElement)(external_wp_blockEditor_namespaceObject.RichText, { |
| 1520 |
tagName: "h2", |
| 1521 |
className: "widget-title", |
| 1522 |
allowedFormats: [], |
| 1523 |
placeholder: (0,external_wp_i18n_namespaceObject.__)('Title'), |
| 1524 |
value: (_attributes$title = attributes.title) !== null && _attributes$title !== void 0 ? _attributes$title : '', |
| 1525 |
onChange: title => setAttributes({ |
| 1526 |
title |
| 1527 |
}) |
| 1528 |
}), (0,external_wp_element_namespaceObject.createElement)(external_wp_blockEditor_namespaceObject.InnerBlocks, null)); |
| 1529 |
} |
| 1530 |
|
| 1531 |
;// CONCATENATED MODULE: ./packages/widgets/build-module/blocks/widget-group/save.js |
| 1532 |
|
| 1533 |
|
| 1534 |
/** |
| 1535 |
* WordPress dependencies |
| 1536 |
*/ |
| 1537 |
|
| 1538 |
function save(_ref) { |
| 1539 |
let { |
| 1540 |
attributes |
| 1541 |
} = _ref; |
| 1542 |
return (0,external_wp_element_namespaceObject.createElement)(external_wp_element_namespaceObject.Fragment, null, (0,external_wp_element_namespaceObject.createElement)(external_wp_blockEditor_namespaceObject.RichText.Content, { |
| 1543 |
tagName: "h2", |
| 1544 |
className: "widget-title", |
| 1545 |
value: attributes.title |
| 1546 |
}), (0,external_wp_element_namespaceObject.createElement)("div", { |
| 1547 |
className: "wp-widget-group__inner-blocks" |
| 1548 |
}, (0,external_wp_element_namespaceObject.createElement)(external_wp_blockEditor_namespaceObject.InnerBlocks.Content, null))); |
| 1549 |
} |
| 1550 |
|
| 1551 |
;// CONCATENATED MODULE: ./packages/widgets/build-module/blocks/widget-group/deprecated.js |
| 1552 |
|
| 1553 |
|
| 1554 |
/** |
| 1555 |
* WordPress dependencies |
| 1556 |
*/ |
| 1557 |
|
| 1558 |
const v1 = { |
| 1559 |
attributes: { |
| 1560 |
title: { |
| 1561 |
type: 'string' |
| 1562 |
} |
| 1563 |
}, |
| 1564 |
supports: { |
| 1565 |
html: false, |
| 1566 |
inserter: true, |
| 1567 |
customClassName: true, |
| 1568 |
reusable: false |
| 1569 |
}, |
| 1570 |
|
| 1571 |
save(_ref) { |
| 1572 |
let { |
| 1573 |
attributes |
| 1574 |
} = _ref; |
| 1575 |
return (0,external_wp_element_namespaceObject.createElement)(external_wp_element_namespaceObject.Fragment, null, (0,external_wp_element_namespaceObject.createElement)(external_wp_blockEditor_namespaceObject.RichText.Content, { |
| 1576 |
tagName: "h2", |
| 1577 |
className: "widget-title", |
| 1578 |
value: attributes.title |
| 1579 |
}), (0,external_wp_element_namespaceObject.createElement)(external_wp_blockEditor_namespaceObject.InnerBlocks.Content, null)); |
| 1580 |
} |
| 1581 |
|
| 1582 |
}; |
| 1583 |
/* harmony default export */ var deprecated = ([v1]); |
| 1584 |
|
| 1585 |
;// CONCATENATED MODULE: ./packages/widgets/build-module/blocks/widget-group/index.js |
| 1586 |
/** |
| 1587 |
* WordPress dependencies |
| 1588 |
*/ |
| 1589 |
|
| 1590 |
|
| 1591 |
|
| 1592 |
/** |
| 1593 |
* Internal dependencies |
| 1594 |
*/ |
| 1595 |
|
| 1596 |
const widget_group_metadata = { |
| 1597 |
apiVersion: 2, |
| 1598 |
name: "core/widget-group", |
| 1599 |
category: "widgets", |
| 1600 |
attributes: { |
| 1601 |
title: { |
| 1602 |
type: "string" |
| 1603 |
} |
| 1604 |
}, |
| 1605 |
supports: { |
| 1606 |
html: false, |
| 1607 |
inserter: true, |
| 1608 |
customClassName: true, |
| 1609 |
reusable: false |
| 1610 |
}, |
| 1611 |
editorStyle: "wp-block-widget-group-editor", |
| 1612 |
style: "wp-block-widget-group" |
| 1613 |
}; |
| 1614 |
|
| 1615 |
|
| 1616 |
|
| 1617 |
const { |
| 1618 |
name: widget_group_name |
| 1619 |
} = widget_group_metadata; |
| 1620 |
|
| 1621 |
const widget_group_settings = { |
| 1622 |
title: (0,external_wp_i18n_namespaceObject.__)('Widget Group'), |
| 1623 |
description: (0,external_wp_i18n_namespaceObject.__)('Create a classic widget layout with a title that’s styled by your theme for your widget areas.'), |
| 1624 |
icon: library_group, |
| 1625 |
__experimentalLabel: _ref => { |
| 1626 |
let { |
| 1627 |
name: label |
| 1628 |
} = _ref; |
| 1629 |
return label; |
| 1630 |
}, |
| 1631 |
edit: edit_Edit, |
| 1632 |
save: save, |
| 1633 |
transforms: { |
| 1634 |
from: [{ |
| 1635 |
type: 'block', |
| 1636 |
isMultiBlock: true, |
| 1637 |
blocks: ['*'], |
| 1638 |
|
| 1639 |
isMatch(attributes, blocks) { |
| 1640 |
// Avoid transforming existing `widget-group` blocks. |
| 1641 |
return !blocks.some(block => block.name === 'core/widget-group'); |
| 1642 |
}, |
| 1643 |
|
| 1644 |
__experimentalConvert(blocks) { |
| 1645 |
// Put the selected blocks inside the new Widget Group's innerBlocks. |
| 1646 |
let innerBlocks = [...blocks.map(block => { |
| 1647 |
return (0,external_wp_blocks_namespaceObject.createBlock)(block.name, block.attributes, block.innerBlocks); |
| 1648 |
})]; // If the first block is a heading then assume this is intended |
| 1649 |
// to be the Widget's "title". |
| 1650 |
|
| 1651 |
const firstHeadingBlock = innerBlocks[0].name === 'core/heading' ? innerBlocks[0] : null; // Remove the first heading block as we're copying |
| 1652 |
// it's content into the Widget Group's title attribute. |
| 1653 |
|
| 1654 |
innerBlocks = innerBlocks.filter(block => block !== firstHeadingBlock); |
| 1655 |
return (0,external_wp_blocks_namespaceObject.createBlock)('core/widget-group', { ...(firstHeadingBlock && { |
| 1656 |
title: firstHeadingBlock.attributes.content |
| 1657 |
}) |
| 1658 |
}, innerBlocks); |
| 1659 |
} |
| 1660 |
|
| 1661 |
}] |
| 1662 |
}, |
| 1663 |
deprecated: deprecated |
| 1664 |
}; |
| 1665 |
|
| 1666 |
;// CONCATENATED MODULE: ./packages/icons/build-module/library/move-to.js |
| 1667 |
|
| 1668 |
|
| 1669 |
/** |
| 1670 |
* WordPress dependencies |
| 1671 |
*/ |
| 1672 |
|
| 1673 |
const moveTo = (0,external_wp_element_namespaceObject.createElement)(external_wp_primitives_namespaceObject.SVG, { |
| 1674 |
xmlns: "http://www.w3.org/2000/svg", |
| 1675 |
viewBox: "0 0 24 24" |
| 1676 |
}, (0,external_wp_element_namespaceObject.createElement)(external_wp_primitives_namespaceObject.Path, { |
| 1677 |
d: "M19.75 9c0-1.257-.565-2.197-1.39-2.858-.797-.64-1.827-1.017-2.815-1.247-1.802-.42-3.703-.403-4.383-.396L11 4.5V6l.177-.001c.696-.006 2.416-.02 4.028.356.887.207 1.67.518 2.216.957.52.416.829.945.829 1.688 0 .592-.167.966-.407 1.23-.255.281-.656.508-1.236.674-1.19.34-2.82.346-4.607.346h-.077c-1.692 0-3.527 0-4.942.404-.732.209-1.424.545-1.935 1.108-.526.579-.796 1.33-.796 2.238 0 1.257.565 2.197 1.39 2.858.797.64 1.827 1.017 2.815 1.247 1.802.42 3.703.403 4.383.396L13 19.5h.714V22L18 18.5 13.714 15v3H13l-.177.001c-.696.006-2.416.02-4.028-.356-.887-.207-1.67-.518-2.216-.957-.52-.416-.829-.945-.829-1.688 0-.592.167-.966.407-1.23.255-.281.656-.508 1.237-.674 1.189-.34 2.819-.346 4.606-.346h.077c1.692 0 3.527 0 4.941-.404.732-.209 1.425-.545 1.936-1.108.526-.579.796-1.33.796-2.238z" |
| 1678 |
})); |
| 1679 |
/* harmony default export */ var move_to = (moveTo); |
| 1680 |
|
| 1681 |
;// CONCATENATED MODULE: ./packages/widgets/build-module/components/move-to-widget-area/index.js |
| 1682 |
|
| 1683 |
|
| 1684 |
/** |
| 1685 |
* WordPress dependencies |
| 1686 |
*/ |
| 1687 |
|
| 1688 |
|
| 1689 |
|
| 1690 |
function MoveToWidgetArea(_ref) { |
| 1691 |
let { |
| 1692 |
currentWidgetAreaId, |
| 1693 |
widgetAreas, |
| 1694 |
onSelect |
| 1695 |
} = _ref; |
| 1696 |
return (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.ToolbarGroup, null, (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.ToolbarItem, null, toggleProps => (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.DropdownMenu, { |
| 1697 |
icon: move_to, |
| 1698 |
label: (0,external_wp_i18n_namespaceObject.__)('Move to widget area'), |
| 1699 |
toggleProps: toggleProps |
| 1700 |
}, _ref2 => { |
| 1701 |
let { |
| 1702 |
onClose |
| 1703 |
} = _ref2; |
| 1704 |
return (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.MenuGroup, { |
| 1705 |
label: (0,external_wp_i18n_namespaceObject.__)('Move to') |
| 1706 |
}, (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.MenuItemsChoice, { |
| 1707 |
choices: widgetAreas.map(widgetArea => ({ |
| 1708 |
value: widgetArea.id, |
| 1709 |
label: widgetArea.name, |
| 1710 |
info: widgetArea.description |
| 1711 |
})), |
| 1712 |
value: currentWidgetAreaId, |
| 1713 |
onSelect: value => { |
| 1714 |
onSelect(value); |
| 1715 |
onClose(); |
| 1716 |
} |
| 1717 |
})); |
| 1718 |
}))); |
| 1719 |
} |
| 1720 |
|
| 1721 |
;// CONCATENATED MODULE: ./packages/widgets/build-module/components/index.js |
| 1722 |
|
| 1723 |
|
| 1724 |
;// CONCATENATED MODULE: ./packages/widgets/build-module/utils.js |
| 1725 |
// @ts-check |
| 1726 |
|
| 1727 |
/** |
| 1728 |
* Get the internal widget id from block. |
| 1729 |
* |
| 1730 |
* @typedef {Object} Attributes |
| 1731 |
* @property {string} __internalWidgetId The internal widget id. |
| 1732 |
* @typedef {Object} Block |
| 1733 |
* @property {Attributes} attributes The attributes of the block. |
| 1734 |
* |
| 1735 |
* @param {Block} block The block. |
| 1736 |
* @return {string} The internal widget id. |
| 1737 |
*/ |
| 1738 |
function getWidgetIdFromBlock(block) { |
| 1739 |
return block.attributes.__internalWidgetId; |
| 1740 |
} |
| 1741 |
/** |
| 1742 |
* Add internal widget id to block's attributes. |
| 1743 |
* |
| 1744 |
* @param {Block} block The block. |
| 1745 |
* @param {string} widgetId The widget id. |
| 1746 |
* @return {Block} The updated block. |
| 1747 |
*/ |
| 1748 |
|
| 1749 |
function addWidgetIdToBlock(block, widgetId) { |
| 1750 |
return { ...block, |
| 1751 |
attributes: { ...(block.attributes || {}), |
| 1752 |
__internalWidgetId: widgetId |
| 1753 |
} |
| 1754 |
}; |
| 1755 |
} |
| 1756 |
|
| 1757 |
;// CONCATENATED MODULE: ./packages/widgets/build-module/register-legacy-widget-variations.js |
| 1758 |
/** |
| 1759 |
* WordPress dependencies |
| 1760 |
*/ |
| 1761 |
|
| 1762 |
|
| 1763 |
|
| 1764 |
function registerLegacyWidgetVariations(settings) { |
| 1765 |
const unsubscribe = (0,external_wp_data_namespaceObject.subscribe)(() => { |
| 1766 |
var _settings$widgetTypes, _select$getWidgetType; |
| 1767 |
|
| 1768 |
const hiddenIds = (_settings$widgetTypes = settings === null || settings === void 0 ? void 0 : settings.widgetTypesToHideFromLegacyWidgetBlock) !== null && _settings$widgetTypes !== void 0 ? _settings$widgetTypes : []; |
| 1769 |
const widgetTypes = (_select$getWidgetType = (0,external_wp_data_namespaceObject.select)(external_wp_coreData_namespaceObject.store).getWidgetTypes({ |
| 1770 |
per_page: -1 |
| 1771 |
})) === null || _select$getWidgetType === void 0 ? void 0 : _select$getWidgetType.filter(widgetType => !hiddenIds.includes(widgetType.id)); |
| 1772 |
|
| 1773 |
if (widgetTypes) { |
| 1774 |
unsubscribe(); |
| 1775 |
(0,external_wp_data_namespaceObject.dispatch)(external_wp_blocks_namespaceObject.store).addBlockVariations('core/legacy-widget', widgetTypes.map(widgetType => ({ |
| 1776 |
name: widgetType.id, |
| 1777 |
title: widgetType.name, |
| 1778 |
description: widgetType.description, |
| 1779 |
attributes: widgetType.is_multi ? { |
| 1780 |
idBase: widgetType.id, |
| 1781 |
instance: {} |
| 1782 |
} : { |
| 1783 |
id: widgetType.id |
| 1784 |
} |
| 1785 |
}))); |
| 1786 |
} |
| 1787 |
}); |
| 1788 |
} |
| 1789 |
|
| 1790 |
;// CONCATENATED MODULE: ./packages/widgets/build-module/index.js |
| 1791 |
/** |
| 1792 |
* WordPress dependencies |
| 1793 |
*/ |
| 1794 |
|
| 1795 |
/** |
| 1796 |
* Internal dependencies |
| 1797 |
*/ |
| 1798 |
|
| 1799 |
|
| 1800 |
|
| 1801 |
|
| 1802 |
|
| 1803 |
/** |
| 1804 |
* Registers the Legacy Widget block. |
| 1805 |
* |
| 1806 |
* Note that for the block to be useful, any scripts required by a widget must |
| 1807 |
* be loaded into the page. |
| 1808 |
* |
| 1809 |
* @param {Object} supports Block support settings. |
| 1810 |
* @see https://developer.wordpress.org/block-editor/how-to-guides/widgets/legacy-widget-block/ |
| 1811 |
*/ |
| 1812 |
|
| 1813 |
function registerLegacyWidgetBlock() { |
| 1814 |
let supports = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
| 1815 |
const { |
| 1816 |
metadata, |
| 1817 |
settings, |
| 1818 |
name |
| 1819 |
} = legacy_widget_namespaceObject; |
| 1820 |
(0,external_wp_blocks_namespaceObject.registerBlockType)({ |
| 1821 |
name, |
| 1822 |
...metadata |
| 1823 |
}, { ...settings, |
| 1824 |
supports: { ...settings.supports, |
| 1825 |
...supports |
| 1826 |
} |
| 1827 |
}); |
| 1828 |
} |
| 1829 |
/** |
| 1830 |
* Registers the Widget Group block. |
| 1831 |
*/ |
| 1832 |
|
| 1833 |
function registerWidgetGroupBlock() { |
| 1834 |
const { |
| 1835 |
metadata, |
| 1836 |
settings, |
| 1837 |
name |
| 1838 |
} = widget_group_namespaceObject; |
| 1839 |
(0,external_wp_blocks_namespaceObject.registerBlockType)({ |
| 1840 |
name, |
| 1841 |
...metadata |
| 1842 |
}, settings); |
| 1843 |
} |
| 1844 |
|
| 1845 |
|
| 1846 |
}(); |
| 1847 |
(window.wp = window.wp || {}).widgets = __webpack_exports__; |
| 1848 |
/******/ })() |
| 1849 |
; |