| 1 |
/******/ (() => { // webpackBootstrap |
| 2 |
/******/ var __webpack_modules__ = ({ |
| 3 |
|
| 4 |
/***/ 677 |
| 5 |
(module) { |
| 6 |
|
| 7 |
module.exports = (function() { return this["React"]; }()); |
| 8 |
|
| 9 |
/***/ }, |
| 10 |
|
| 11 |
/***/ 419 |
| 12 |
(module) { |
| 13 |
|
| 14 |
module.exports = (function() { return this["lodash"]; }()); |
| 15 |
|
| 16 |
/***/ }, |
| 17 |
|
| 18 |
/***/ 631 |
| 19 |
(module) { |
| 20 |
|
| 21 |
module.exports = (function() { return this["wp"]["apiFetch"]; }()); |
| 22 |
|
| 23 |
/***/ }, |
| 24 |
|
| 25 |
/***/ 89 |
| 26 |
(module) { |
| 27 |
|
| 28 |
module.exports = (function() { return this["wp"]["blockEditor"]; }()); |
| 29 |
|
| 30 |
/***/ }, |
| 31 |
|
| 32 |
/***/ 545 |
| 33 |
(module) { |
| 34 |
|
| 35 |
module.exports = (function() { return this["wp"]["blocks"]; }()); |
| 36 |
|
| 37 |
/***/ }, |
| 38 |
|
| 39 |
/***/ 959 |
| 40 |
(module) { |
| 41 |
|
| 42 |
module.exports = (function() { return this["wp"]["components"]; }()); |
| 43 |
|
| 44 |
/***/ }, |
| 45 |
|
| 46 |
/***/ 987 |
| 47 |
(module) { |
| 48 |
|
| 49 |
module.exports = (function() { return this["wp"]["data"]; }()); |
| 50 |
|
| 51 |
/***/ }, |
| 52 |
|
| 53 |
/***/ 2 |
| 54 |
(module) { |
| 55 |
|
| 56 |
module.exports = (function() { return this["wp"]["editor"]; }()); |
| 57 |
|
| 58 |
/***/ }, |
| 59 |
|
| 60 |
/***/ 601 |
| 61 |
(module) { |
| 62 |
|
| 63 |
module.exports = (function() { return this["wp"]["element"]; }()); |
| 64 |
|
| 65 |
/***/ }, |
| 66 |
|
| 67 |
/***/ 873 |
| 68 |
(module) { |
| 69 |
|
| 70 |
module.exports = (function() { return this["wp"]["hooks"]; }()); |
| 71 |
|
| 72 |
/***/ }, |
| 73 |
|
| 74 |
/***/ 75 |
| 75 |
(module) { |
| 76 |
|
| 77 |
module.exports = (function() { return this["wp"]["i18n"]; }()); |
| 78 |
|
| 79 |
/***/ }, |
| 80 |
|
| 81 |
/***/ 933 |
| 82 |
(module) { |
| 83 |
|
| 84 |
module.exports = (function() { return this["wp"]["primitives"]; }()); |
| 85 |
|
| 86 |
/***/ } |
| 87 |
|
| 88 |
/******/ }); |
| 89 |
/************************************************************************/ |
| 90 |
/******/ // The module cache |
| 91 |
/******/ const __webpack_module_cache__ = {}; |
| 92 |
/******/ |
| 93 |
/******/ // The require function |
| 94 |
/******/ function __webpack_require__(moduleId) { |
| 95 |
/******/ // Check if module is in cache |
| 96 |
/******/ const cachedModule = __webpack_module_cache__[moduleId]; |
| 97 |
/******/ if (cachedModule !== undefined) { |
| 98 |
/******/ return cachedModule.exports; |
| 99 |
/******/ } |
| 100 |
/******/ // Create a new module (and put it into the cache) |
| 101 |
/******/ const module = __webpack_module_cache__[moduleId] = { |
| 102 |
/******/ // no module.id needed |
| 103 |
/******/ // no module.loaded needed |
| 104 |
/******/ exports: {} |
| 105 |
/******/ }; |
| 106 |
/******/ |
| 107 |
/******/ // Execute the module function |
| 108 |
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); |
| 109 |
/******/ |
| 110 |
/******/ // Return the exports of the module |
| 111 |
/******/ return module.exports; |
| 112 |
/******/ } |
| 113 |
/******/ |
| 114 |
/************************************************************************/ |
| 115 |
/******/ /* webpack/runtime/compat get default export */ |
| 116 |
/******/ // getDefaultExport function for compatibility with non-harmony modules |
| 117 |
/******/ __webpack_require__.n = (module) => { |
| 118 |
/******/ const getter = module && module.__esModule ? |
| 119 |
/******/ () => (module['default']) : |
| 120 |
/******/ () => (module); |
| 121 |
/******/ __webpack_require__.d(getter, { a: getter }); |
| 122 |
/******/ return getter; |
| 123 |
/******/ }; |
| 124 |
/******/ |
| 125 |
/******/ /* webpack/runtime/concatenation wrap */ |
| 126 |
/******/ // wrap a concatenated module body as a lazy, memoized accessor; mod is |
| 127 |
/******/ // set before the body runs so re-entrant calls (require cycles) observe |
| 128 |
/******/ // the partial exports like Node.js |
| 129 |
/******/ __webpack_require__.cw = (body) => { |
| 130 |
/******/ var mod; |
| 131 |
/******/ return () => { |
| 132 |
/******/ if (body) { |
| 133 |
/******/ var fn = body; |
| 134 |
/******/ body = 0; |
| 135 |
/******/ mod = { exports: {} }; |
| 136 |
/******/ fn.call(mod.exports, mod, mod.exports); |
| 137 |
/******/ } |
| 138 |
/******/ return mod.exports; |
| 139 |
/******/ }; |
| 140 |
/******/ }; |
| 141 |
/******/ |
| 142 |
/******/ /* webpack/runtime/define property getters */ |
| 143 |
/******/ // define getter/value functions for harmony exports |
| 144 |
/******/ __webpack_require__.d = (exports, definition) => { |
| 145 |
/******/ for(var key in definition) { |
| 146 |
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { |
| 147 |
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); |
| 148 |
/******/ } |
| 149 |
/******/ } |
| 150 |
/******/ }; |
| 151 |
/******/ |
| 152 |
/******/ /* webpack/runtime/hasOwnProperty shorthand */ |
| 153 |
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)); |
| 154 |
/******/ |
| 155 |
/************************************************************************/ |
| 156 |
let __webpack_exports__ = {}; |
| 157 |
// This entry needs to be wrapped in an IIFE because it needs to be in strict mode. |
| 158 |
(() => { |
| 159 |
"use strict"; |
| 160 |
|
| 161 |
// MODULE: ./node_modules/react/cjs/react-jsx-runtime.production.min.js |
| 162 |
var react_jsx_runtime_production_min_namespaceFn = /*#__PURE__*/__webpack_require__.cw(function(module, exports) { |
| 163 |
/** |
| 164 |
* @license React |
| 165 |
* react-jsx-runtime.production.min.js |
| 166 |
* |
| 167 |
* Copyright (c) Facebook, Inc. and its affiliates. |
| 168 |
* |
| 169 |
* This source code is licensed under the MIT license found in the |
| 170 |
* LICENSE file in the root directory of this source tree. |
| 171 |
*/ |
| 172 |
var f=(external_React_namespaceFn()),k=Symbol.for("react.element"),l=Symbol.for("react.fragment"),m=Object.prototype.hasOwnProperty,n=f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,p={key:!0,ref:!0,__self:!0,__source:!0}; |
| 173 |
function q(c,a,g){var b,d={},e=null,h=null;void 0!==g&&(e=""+g);void 0!==a.key&&(e=""+a.key);void 0!==a.ref&&(h=a.ref);for(b in a)m.call(a,b)&&!p.hasOwnProperty(b)&&(d[b]=a[b]);if(c&&c.defaultProps)for(b in a=c.defaultProps,a)void 0===d[b]&&(d[b]=a[b]);return{$$typeof:k,type:c,key:e,ref:h,props:d,_owner:n.current}}exports.Fragment=l;exports.jsx=q;exports.jsxs=q; |
| 174 |
|
| 175 |
}); |
| 176 |
|
| 177 |
// MODULE: ./node_modules/react/jsx-runtime.js |
| 178 |
var jsx_runtime_namespaceFn = /*#__PURE__*/__webpack_require__.cw(function(module, exports) { |
| 179 |
|
| 180 |
|
| 181 |
if (true) { |
| 182 |
module.exports = (react_jsx_runtime_production_min_namespaceFn()); |
| 183 |
} else // removed by dead control flow |
| 184 |
{} |
| 185 |
|
| 186 |
}); |
| 187 |
|
| 188 |
// EXTERNAL MODULE: external "React" |
| 189 |
var external_React_namespaceFn = () => { |
| 190 |
return __webpack_require__(677); |
| 191 |
}; |
| 192 |
|
| 193 |
// EXTERNAL MODULE: external {"this":["wp","blocks"]} |
| 194 |
var external_this_wp_blocks_ = __webpack_require__(545); |
| 195 |
// EXTERNAL MODULE: external {"this":["wp","primitives"]} |
| 196 |
var external_this_wp_primitives_ = __webpack_require__(933); |
| 197 |
;// ./node_modules/react/jsx-runtime.js |
| 198 |
jsx_runtime_namespaceFn(); |
| 199 |
|
| 200 |
;// ./node_modules/@wpsyntex/polylang-react-library/build/icons/translation.js |
| 201 |
/** |
| 202 |
* Translation icon - translation Dashicon. |
| 203 |
*/ |
| 204 |
|
| 205 |
/** |
| 206 |
* WordPress dependencies |
| 207 |
*/ |
| 208 |
|
| 209 |
|
| 210 |
const isPrimitivesComponents = 'undefined' !== typeof wp.primitives; |
| 211 |
const translation = isPrimitivesComponents ? /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(external_this_wp_primitives_.SVG, { |
| 212 |
width: "20", |
| 213 |
height: "20", |
| 214 |
xmlns: "http://www.w3.org/2000/svg", |
| 215 |
viewBox: "0 0 20 20", |
| 216 |
children: /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(external_this_wp_primitives_.Path, { |
| 217 |
d: "M11 7H9.49c-.63 0-1.25.3-1.59.7L7 5H4.13l-2.39 7h1.69l.74-2H7v4H2c-1.1 0-2-.9-2-2V5c0-1.1.9-2 2-2h7c1.1 0 2 .9 2 2v2zM6.51 9H4.49l1-2.93zM10 8h7c1.1 0 2 .9 2 2v7c0 1.1-.9 2-2 2h-7c-1.1 0-2-.9-2-2v-7c0-1.1.9-2 2-2zm7.25 5v-1.08h-3.17V9.75h-1.16v2.17H9.75V13h1.28c.11.85.56 1.85 1.28 2.62-.87.36-1.89.62-2.31.62-.01.02.22.97.2 1.46.84 0 2.21-.5 3.28-1.15 1.09.65 2.48 1.15 3.34 1.15-.02-.49.2-1.44.2-1.46-.43 0-1.49-.27-2.38-.63.7-.77 1.14-1.77 1.25-2.61h1.36zm-3.81 1.93c-.5-.46-.85-1.13-1.01-1.93h2.09c-.17.8-.51 1.47-1 1.93l-.04.03s-.03-.02-.04-.03z" |
| 218 |
}) |
| 219 |
}) : 'translation'; |
| 220 |
/* harmony default export */ const icons_translation = (translation); |
| 221 |
// EXTERNAL MODULE: external {"this":["wp","i18n"]} |
| 222 |
var external_this_wp_i18n_ = __webpack_require__(75); |
| 223 |
// EXTERNAL MODULE: external {"this":["wp","blockEditor"]} |
| 224 |
var external_this_wp_blockEditor_ = __webpack_require__(89); |
| 225 |
// EXTERNAL MODULE: external {"this":["wp","components"]} |
| 226 |
var external_this_wp_components_ = __webpack_require__(959); |
| 227 |
// EXTERNAL MODULE: external "lodash" |
| 228 |
var external_lodash_ = __webpack_require__(419); |
| 229 |
;// ./js/src/blocks/language-switcher-edit.js |
| 230 |
/** |
| 231 |
* Language switcher block edit. |
| 232 |
*/ |
| 233 |
|
| 234 |
/** |
| 235 |
* External dependencies |
| 236 |
*/ |
| 237 |
|
| 238 |
|
| 239 |
/** |
| 240 |
* WordPress dependencies |
| 241 |
*/ |
| 242 |
|
| 243 |
|
| 244 |
const i18nAttributeStrings = pll_block_editor_blocks_settings; |
| 245 |
function createLanguageSwitcherEdit(props) { |
| 246 |
const createToggleAttribute = function (propName) { |
| 247 |
return () => { |
| 248 |
const value = props.attributes[propName]; |
| 249 |
const { |
| 250 |
setAttributes |
| 251 |
} = props; |
| 252 |
let updatedAttributes = { |
| 253 |
[propName]: !value |
| 254 |
}; |
| 255 |
let forcedAttributeName; |
| 256 |
let forcedAttributeUnchecked; |
| 257 |
|
| 258 |
// Both show_names and show_flags attributes can't be unchecked together. |
| 259 |
switch (propName) { |
| 260 |
case 'show_names': |
| 261 |
forcedAttributeName = 'show_flags'; |
| 262 |
forcedAttributeUnchecked = !props.attributes[forcedAttributeName]; |
| 263 |
break; |
| 264 |
case 'show_flags': |
| 265 |
forcedAttributeName = 'show_names'; |
| 266 |
forcedAttributeUnchecked = !props.attributes[forcedAttributeName]; |
| 267 |
break; |
| 268 |
} |
| 269 |
if ('show_names' === propName || 'show_flags' === propName) { |
| 270 |
if (value && forcedAttributeUnchecked) { |
| 271 |
updatedAttributes = (0,external_lodash_.assign)(updatedAttributes, { |
| 272 |
[forcedAttributeName]: forcedAttributeUnchecked |
| 273 |
}); |
| 274 |
} |
| 275 |
} |
| 276 |
setAttributes(updatedAttributes); |
| 277 |
}; |
| 278 |
}; |
| 279 |
const toggleDropdown = createToggleAttribute('dropdown'); |
| 280 |
const toggleShowNames = createToggleAttribute('show_names'); |
| 281 |
const toggleShowFlags = createToggleAttribute('show_flags'); |
| 282 |
const toggleForceHome = createToggleAttribute('force_home'); |
| 283 |
const toggleHideCurrent = createToggleAttribute('hide_current'); |
| 284 |
const toggleHideIfNoTranslation = createToggleAttribute('hide_if_no_translation'); |
| 285 |
const { |
| 286 |
dropdown, |
| 287 |
show_names, |
| 288 |
show_flags, |
| 289 |
force_home, |
| 290 |
hide_current, |
| 291 |
hide_if_no_translation |
| 292 |
} = props.attributes; |
| 293 |
function ToggleControlDropdown() { |
| 294 |
return /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(external_this_wp_components_.ToggleControl, { |
| 295 |
label: i18nAttributeStrings.dropdown, |
| 296 |
checked: dropdown, |
| 297 |
onChange: toggleDropdown |
| 298 |
}); |
| 299 |
} |
| 300 |
function ToggleControlShowNames() { |
| 301 |
return /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(external_this_wp_components_.ToggleControl, { |
| 302 |
label: i18nAttributeStrings.show_names, |
| 303 |
checked: show_names // eslint-disable-line camelcase |
| 304 |
, |
| 305 |
onChange: toggleShowNames |
| 306 |
}); |
| 307 |
} |
| 308 |
function ToggleControlShowFlags() { |
| 309 |
return /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(external_this_wp_components_.ToggleControl, { |
| 310 |
label: i18nAttributeStrings.show_flags, |
| 311 |
checked: show_flags // eslint-disable-line camelcase |
| 312 |
, |
| 313 |
onChange: toggleShowFlags |
| 314 |
}); |
| 315 |
} |
| 316 |
function ToggleControlForceHome() { |
| 317 |
return /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(external_this_wp_components_.ToggleControl, { |
| 318 |
label: i18nAttributeStrings.force_home, |
| 319 |
checked: force_home // eslint-disable-line camelcase |
| 320 |
, |
| 321 |
onChange: toggleForceHome |
| 322 |
}); |
| 323 |
} |
| 324 |
function ToggleControlHideCurrent() { |
| 325 |
return /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(external_this_wp_components_.ToggleControl, { |
| 326 |
label: i18nAttributeStrings.hide_current, |
| 327 |
checked: hide_current // eslint-disable-line camelcase |
| 328 |
, |
| 329 |
onChange: toggleHideCurrent |
| 330 |
}); |
| 331 |
} |
| 332 |
function ToggleControlHideIfNoTranslations() { |
| 333 |
return /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(external_this_wp_components_.ToggleControl, { |
| 334 |
label: i18nAttributeStrings.hide_if_no_translation, |
| 335 |
checked: hide_if_no_translation // eslint-disable-line camelcase |
| 336 |
, |
| 337 |
onChange: toggleHideIfNoTranslation |
| 338 |
}); |
| 339 |
} |
| 340 |
return { |
| 341 |
ToggleControlDropdown, |
| 342 |
ToggleControlShowNames, |
| 343 |
ToggleControlShowFlags, |
| 344 |
ToggleControlForceHome, |
| 345 |
ToggleControlHideCurrent, |
| 346 |
ToggleControlHideIfNoTranslations |
| 347 |
}; |
| 348 |
} |
| 349 |
// EXTERNAL MODULE: external {"this":["wp","element"]} |
| 350 |
var external_this_wp_element_ = __webpack_require__(601); |
| 351 |
// EXTERNAL MODULE: external {"this":["wp","data"]} |
| 352 |
var external_this_wp_data_ = __webpack_require__(987); |
| 353 |
;// ./js/src/blocks/hooks/use-current-language-with-editor-context.js |
| 354 |
/** |
| 355 |
* WordPress dependencies |
| 356 |
*/ |
| 357 |
|
| 358 |
|
| 359 |
/** |
| 360 |
* Finds a language by slug. |
| 361 |
* |
| 362 |
* @param {Array} languages The languages list. |
| 363 |
* @param {string} slug The language slug. |
| 364 |
* @return {Object|null} The language, `null` if not found. |
| 365 |
*/ |
| 366 |
const findLanguageBySlug = (languages, slug) => { |
| 367 |
if (!languages || !slug) { |
| 368 |
return null; |
| 369 |
} |
| 370 |
const currentLanguage = languages.find(language => { |
| 371 |
return language.slug === slug; |
| 372 |
}); |
| 373 |
return currentLanguage ? currentLanguage : null; |
| 374 |
}; |
| 375 |
|
| 376 |
/** |
| 377 |
* Resolves the current language in block editor contexts. |
| 378 |
* |
| 379 |
* The widgets editor does not load `@wordpress/editor`, so the `core/editor` |
| 380 |
* store may be unavailable. In that context, fall back to the current language |
| 381 |
* slug injected by PHP (default language when none is set). |
| 382 |
* |
| 383 |
* @param {Array} languages The languages list. |
| 384 |
* @return {Object|null} The current language, `null` if not found. |
| 385 |
*/ |
| 386 |
const useCurrentLanguageWithEditorContext = languages => { |
| 387 |
return (0,external_this_wp_data_.useSelect)(select => { |
| 388 |
if (!languages) { |
| 389 |
return null; |
| 390 |
} |
| 391 |
const editorStore = select('core/editor'); |
| 392 |
if (!editorStore) { |
| 393 |
return findLanguageBySlug(languages, pllEditorCurrentLanguageSlug // eslint-disable-line no-undef |
| 394 |
); |
| 395 |
} |
| 396 |
const currentPost = editorStore.getCurrentPost(); |
| 397 |
if (!currentPost) { |
| 398 |
return null; |
| 399 |
} |
| 400 |
const currentLanguageSlug = currentPost.lang ?? pllEditorCurrentLanguageSlug; // eslint-disable-line no-undef |
| 401 |
|
| 402 |
return findLanguageBySlug(languages, currentLanguageSlug); |
| 403 |
}, [languages]); |
| 404 |
}; |
| 405 |
;// ./js/src/blocks/languages-context.js |
| 406 |
/** |
| 407 |
* WordPress dependencies. |
| 408 |
*/ |
| 409 |
|
| 410 |
|
| 411 |
/** |
| 412 |
* Context for the languages. |
| 413 |
* |
| 414 |
* @type {React.Context<null>} |
| 415 |
*/ |
| 416 |
const LanguagesContext = (0,external_this_wp_element_.createContext)(null); |
| 417 |
;// ./js/src/blocks/hooks/use-memoized-switcher-label.js |
| 418 |
/** |
| 419 |
* WordPress dependencies |
| 420 |
*/ |
| 421 |
// '@wordpress/element' is provided by WordPress core. |
| 422 |
// eslint-disable-next-line import/no-extraneous-dependencies |
| 423 |
|
| 424 |
|
| 425 |
/** |
| 426 |
* Hook to memoize the switcher label. |
| 427 |
* |
| 428 |
* @param {Object} language The language object. |
| 429 |
* @param {boolean} showFlags Whether to show the flags. |
| 430 |
* @param {boolean} showNames Whether to show the names. |
| 431 |
* @return {Object} The memoized switcher label containing the text and the flag. |
| 432 |
*/ |
| 433 |
const useMemoizedSwitcherLabel = (language, showFlags, showNames) => { |
| 434 |
const { |
| 435 |
text, |
| 436 |
flag |
| 437 |
} = (0,external_this_wp_element_.useMemo)(() => { |
| 438 |
let memoizedText = ''; |
| 439 |
if (showNames) { |
| 440 |
if (showFlags) { |
| 441 |
memoizedText = ` ${language.name}`; |
| 442 |
} else { |
| 443 |
memoizedText = language.name; |
| 444 |
} |
| 445 |
} |
| 446 |
const memoizedFlag = showFlags ? language.flag : ''; |
| 447 |
return { |
| 448 |
text: memoizedText, |
| 449 |
flag: memoizedFlag |
| 450 |
}; |
| 451 |
}, [language, showFlags, showNames]); |
| 452 |
return { |
| 453 |
text, |
| 454 |
flag |
| 455 |
}; |
| 456 |
}; |
| 457 |
;// ./js/src/blocks/language-switcher/components/switcher-list-element.js |
| 458 |
/** |
| 459 |
* Internal dependencies |
| 460 |
*/ |
| 461 |
|
| 462 |
|
| 463 |
/** |
| 464 |
* Switcher list element component. |
| 465 |
* |
| 466 |
* @param {Object} props Component props. |
| 467 |
* @param {Object} props.language Language object. |
| 468 |
* @param {boolean} props.showFlags Whether to show the flags. |
| 469 |
* @param {boolean} props.showNames Whether to show the names. |
| 470 |
* @return {ReactElement} The Switcher element component. |
| 471 |
*/ |
| 472 |
|
| 473 |
const SwitcherListElement = ({ |
| 474 |
language, |
| 475 |
showFlags, |
| 476 |
showNames |
| 477 |
}) => { |
| 478 |
const { |
| 479 |
text, |
| 480 |
flag |
| 481 |
} = useMemoizedSwitcherLabel(language, showFlags, showNames); |
| 482 |
return /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsxs)("li", { |
| 483 |
children: [/*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)("span", { |
| 484 |
dangerouslySetInnerHTML: { |
| 485 |
__html: flag |
| 486 |
} |
| 487 |
}), " ", text, " "] |
| 488 |
}); |
| 489 |
}; |
| 490 |
;// ./js/src/blocks/language-switcher/components/switcher-ui.js |
| 491 |
/** |
| 492 |
* Internal dependencies |
| 493 |
*/ |
| 494 |
|
| 495 |
|
| 496 |
/** |
| 497 |
* Switcher UI component. |
| 498 |
* |
| 499 |
* @param {Object} props The component props. |
| 500 |
* @param {Array} props.languages The languages to display. |
| 501 |
* @param {boolean} props.showFlags Whether to show the flags. |
| 502 |
* @param {boolean} props.showNames Whether to show the names. |
| 503 |
* @param {boolean} props.isDropdown Whether to show the dropdown. |
| 504 |
* @return {ReactElement} The Switcher UI component. |
| 505 |
*/ |
| 506 |
|
| 507 |
const SwitcherUI = ({ |
| 508 |
languages, |
| 509 |
showFlags, |
| 510 |
showNames, |
| 511 |
isDropdown |
| 512 |
}) => { |
| 513 |
if (isDropdown) { |
| 514 |
return /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)("select", { |
| 515 |
children: languages.map(language => { |
| 516 |
return /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)("option", { |
| 517 |
value: language.slug, |
| 518 |
children: language.name |
| 519 |
}, language.slug); |
| 520 |
}) |
| 521 |
}); |
| 522 |
} |
| 523 |
return /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)("ul", { |
| 524 |
children: languages.map(language => { |
| 525 |
return /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(SwitcherListElement, { |
| 526 |
language: language, |
| 527 |
showFlags: showFlags, |
| 528 |
showNames: showNames |
| 529 |
}, language.slug); |
| 530 |
}) |
| 531 |
}); |
| 532 |
}; |
| 533 |
;// ./node_modules/@wpsyntex/polylang-react-library/build/hooks/use-curated-languages.js |
| 534 |
/** |
| 535 |
* WordPress dependencies |
| 536 |
*/ |
| 537 |
|
| 538 |
|
| 539 |
/** |
| 540 |
* Hook to curate the languages. |
| 541 |
* Returns an array of languages ensuring that the current language is always the first one. |
| 542 |
* |
| 543 |
* @param {Object[]} languages The languages. |
| 544 |
* @param {Object} currentLanguage The current language. |
| 545 |
* @param {boolean} reduceToOneItem Whether to reduce the languages to one item. |
| 546 |
* @return {Object[]} The curated languages. |
| 547 |
*/ |
| 548 |
const useCuratedLanguages = (languages, currentLanguage, reduceToOneItem) => { |
| 549 |
const curatedLanguages = (0,external_this_wp_element_.useMemo)(() => { |
| 550 |
if (!currentLanguage) { |
| 551 |
return []; |
| 552 |
} |
| 553 |
if (reduceToOneItem) { |
| 554 |
return [currentLanguage]; |
| 555 |
} |
| 556 |
return [currentLanguage, ...languages.filter(language => { |
| 557 |
return language.slug !== currentLanguage.slug; |
| 558 |
})]; |
| 559 |
}, [languages, currentLanguage, reduceToOneItem]); |
| 560 |
return curatedLanguages; |
| 561 |
}; |
| 562 |
;// ./js/src/blocks/language-switcher/components/switcher-container.js |
| 563 |
/** |
| 564 |
* WordPress dependencies |
| 565 |
*/ |
| 566 |
|
| 567 |
|
| 568 |
/** |
| 569 |
* Internal dependencies |
| 570 |
*/ |
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
/** |
| 577 |
* Switcher container component. |
| 578 |
* |
| 579 |
* @param {Object} props The component props. |
| 580 |
* @param {Object} props.attributes The block attributes. |
| 581 |
* @return {ReactElement} The Switcher component. |
| 582 |
*/ |
| 583 |
|
| 584 |
const SwitcherContainer = ({ |
| 585 |
attributes |
| 586 |
}) => { |
| 587 |
const { |
| 588 |
dropdown, |
| 589 |
show_flags, |
| 590 |
show_names |
| 591 |
} = attributes; |
| 592 |
const { |
| 593 |
languages |
| 594 |
} = (0,external_this_wp_element_.useContext)(LanguagesContext); |
| 595 |
const currentLanguage = useCurrentLanguageWithEditorContext(languages); |
| 596 |
const curatedLanguages = useCuratedLanguages(languages, currentLanguage, dropdown); |
| 597 |
return /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(SwitcherUI, { |
| 598 |
languages: curatedLanguages, |
| 599 |
showFlags: show_flags, |
| 600 |
showNames: show_names, |
| 601 |
isDropdown: dropdown |
| 602 |
}); |
| 603 |
}; |
| 604 |
// EXTERNAL MODULE: external {"this":["wp","apiFetch"]} |
| 605 |
var external_this_wp_apiFetch_ = __webpack_require__(631); |
| 606 |
var external_this_wp_apiFetch_default = /*#__PURE__*/__webpack_require__.n(external_this_wp_apiFetch_); |
| 607 |
;// ./node_modules/@wpsyntex/polylang-react-library/build/hooks/use-languages-list.js |
| 608 |
/** |
| 609 |
* WordPress dependencies |
| 610 |
*/ |
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
/** |
| 615 |
* Custom hook to get the languages list. |
| 616 |
* |
| 617 |
* @return {Array|null} The languages list, `null` if not loaded yet. |
| 618 |
*/ |
| 619 |
const useLanguagesList = () => { |
| 620 |
const [languages, setLanguages] = (0,external_this_wp_element_.useState)(null); |
| 621 |
(0,external_this_wp_element_.useEffect)(() => { |
| 622 |
external_this_wp_apiFetch_default()({ |
| 623 |
path: '/pll/v1/languages', |
| 624 |
method: 'GET' |
| 625 |
}).then(response => setLanguages(response)); |
| 626 |
}, []); |
| 627 |
return languages; |
| 628 |
}; |
| 629 |
;// ./js/src/blocks/language-switcher/edit.js |
| 630 |
/** |
| 631 |
* Edit callback for language switcher block. |
| 632 |
*/ |
| 633 |
|
| 634 |
/** |
| 635 |
* WordPress dependencies |
| 636 |
*/ |
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
/** |
| 642 |
* Internal dependencies |
| 643 |
*/ |
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
/** |
| 650 |
* Edit callback for language switcher block. |
| 651 |
* |
| 652 |
* @param {Object} props Block properties. |
| 653 |
* @return {ReactElement} The block content and controls. |
| 654 |
*/ |
| 655 |
|
| 656 |
const Edit = props => { |
| 657 |
const { |
| 658 |
dropdown |
| 659 |
} = props.attributes; |
| 660 |
const languages = useLanguagesList(); |
| 661 |
const { |
| 662 |
ToggleControlDropdown, |
| 663 |
ToggleControlShowNames, |
| 664 |
ToggleControlShowFlags, |
| 665 |
ToggleControlForceHome, |
| 666 |
ToggleControlHideCurrent, |
| 667 |
ToggleControlHideIfNoTranslations |
| 668 |
} = createLanguageSwitcherEdit(props); |
| 669 |
return /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsxs)("div", { |
| 670 |
...(0,external_this_wp_blockEditor_.useBlockProps)(), |
| 671 |
children: [/*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(external_this_wp_blockEditor_.InspectorControls, { |
| 672 |
children: /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsxs)(external_this_wp_components_.PanelBody, { |
| 673 |
title: (0,external_this_wp_i18n_.__)('Language switcher settings', 'polylang'), |
| 674 |
children: [/*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(ToggleControlDropdown, {}), !dropdown && /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(ToggleControlShowNames, {}), !dropdown && /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(ToggleControlShowFlags, {}), /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(ToggleControlForceHome, {}), !dropdown && /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(ToggleControlHideCurrent, {}), /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(ToggleControlHideIfNoTranslations, {})] |
| 675 |
}) |
| 676 |
}), /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(external_this_wp_components_.Disabled, { |
| 677 |
children: /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(LanguagesContext.Provider, { |
| 678 |
value: { |
| 679 |
languages |
| 680 |
}, |
| 681 |
children: /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(SwitcherContainer, { |
| 682 |
attributes: props.attributes |
| 683 |
}) |
| 684 |
}) |
| 685 |
})] |
| 686 |
}); |
| 687 |
}; |
| 688 |
;// ./src/modules/Blocks/Language_Switcher/Standard/block.json |
| 689 |
const block_namespaceObject = /*#__PURE__*/JSON.parse('{"UU":"polylang/language-switcher"}'); |
| 690 |
;// ./js/src/blocks/language-switcher/index.js |
| 691 |
/** |
| 692 |
* Register language switcher block. |
| 693 |
*/ |
| 694 |
|
| 695 |
/** |
| 696 |
* WordPress dependencies |
| 697 |
*/ |
| 698 |
|
| 699 |
|
| 700 |
/** |
| 701 |
* Internal dependencies |
| 702 |
*/ |
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
(0,external_this_wp_blocks_.registerBlockType)(block_namespaceObject.UU, { |
| 707 |
icon: icons_translation, |
| 708 |
edit: Edit |
| 709 |
}); |
| 710 |
// EXTERNAL MODULE: external {"this":["wp","hooks"]} |
| 711 |
var external_this_wp_hooks_ = __webpack_require__(873); |
| 712 |
;// ./js/src/blocks/navigation-language-switcher/components/switcher-link-element.js |
| 713 |
/** |
| 714 |
* Internal dependencies |
| 715 |
*/ |
| 716 |
|
| 717 |
|
| 718 |
/** |
| 719 |
* Switcher link element component. |
| 720 |
* |
| 721 |
* @param {Object} props Component props. |
| 722 |
* @param {Object} props.language Language object. |
| 723 |
* @param {boolean} props.isTopLevel Whether the language is the top level language. |
| 724 |
* @param {boolean} props.showFlags Whether to show the flags. |
| 725 |
* @param {boolean} props.showNames Whether to show the names. |
| 726 |
* @return {ReactElement} The Switcher element component. |
| 727 |
*/ |
| 728 |
|
| 729 |
const SwitcherLinkElement = ({ |
| 730 |
language, |
| 731 |
isTopLevel, |
| 732 |
showFlags, |
| 733 |
showNames |
| 734 |
}) => { |
| 735 |
const { |
| 736 |
text, |
| 737 |
flag |
| 738 |
} = useMemoizedSwitcherLabel(language, showFlags, showNames); |
| 739 |
const prefix = isTopLevel ? '' : ' '; |
| 740 |
return ( |
| 741 |
/*#__PURE__*/ |
| 742 |
// eslint-disable-next-line jsx-a11y/anchor-is-valid |
| 743 |
(0,react_jsx_runtime_production_min_namespaceFn().jsxs)("a", { |
| 744 |
href: '#', |
| 745 |
children: [prefix, /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)("span", { |
| 746 |
dangerouslySetInnerHTML: { |
| 747 |
__html: flag |
| 748 |
} |
| 749 |
}), " ", text, " "] |
| 750 |
}) |
| 751 |
); |
| 752 |
}; |
| 753 |
;// ./node_modules/@wpsyntex/polylang-react-library/build/icons/submenu.js |
| 754 |
/** |
| 755 |
* Submenu icon |
| 756 |
*/ |
| 757 |
|
| 758 |
/** |
| 759 |
* WordPress dependencies |
| 760 |
*/ |
| 761 |
|
| 762 |
|
| 763 |
const submenu_isPrimitivesComponents = 'undefined' !== typeof wp.primitives; |
| 764 |
const SubmenuIcon = () => submenu_isPrimitivesComponents ? /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(external_this_wp_primitives_.SVG, { |
| 765 |
xmlns: "http://www.w3.org/2000/svg", |
| 766 |
width: "12", |
| 767 |
height: "12", |
| 768 |
viewBox: "0 0 12 12", |
| 769 |
fill: "none", |
| 770 |
children: /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(external_this_wp_primitives_.Path, { |
| 771 |
d: "M1.50002 4L6.00002 8L10.5 4", |
| 772 |
strokeWidth: "1.5" |
| 773 |
}) |
| 774 |
}) : 'submenu'; |
| 775 |
/* harmony default export */ const submenu = (SubmenuIcon); |
| 776 |
;// ./js/src/blocks/navigation-language-switcher/components/switcher-ui.js |
| 777 |
/** |
| 778 |
* WordPress dependencies |
| 779 |
*/ |
| 780 |
|
| 781 |
|
| 782 |
/** |
| 783 |
* Internal dependencies |
| 784 |
*/ |
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
/** |
| 789 |
* Switcher UI component. |
| 790 |
* |
| 791 |
* @param {Object} props The component props. |
| 792 |
* @param {Array} props.languages The languages to display. |
| 793 |
* @param {boolean} props.showFlags Whether to show the flags. |
| 794 |
* @param {boolean} props.showNames Whether to show the names. |
| 795 |
* @param {boolean} props.withSubmenuIcon Whether to show the submenu icon. |
| 796 |
* @return {ReactElement} The Switcher UI component. |
| 797 |
*/ |
| 798 |
|
| 799 |
const switcher_ui_SwitcherUI = ({ |
| 800 |
languages, |
| 801 |
showFlags, |
| 802 |
showNames, |
| 803 |
withSubmenuIcon |
| 804 |
}) => { |
| 805 |
return /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)((react_jsx_runtime_production_min_namespaceFn().Fragment), { |
| 806 |
children: languages && languages.map(language => { |
| 807 |
return /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsxs)(external_this_wp_element_.Fragment, { |
| 808 |
children: [/*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(SwitcherLinkElement, { |
| 809 |
language: language, |
| 810 |
isTopLevel: languages.indexOf(language) === 0, |
| 811 |
showFlags: showFlags, |
| 812 |
showNames: showNames |
| 813 |
}), withSubmenuIcon && /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)("span", { |
| 814 |
className: "wp-block-navigation__submenu-icon", |
| 815 |
children: /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(submenu, {}) |
| 816 |
})] |
| 817 |
}, language.slug); |
| 818 |
}) |
| 819 |
}); |
| 820 |
}; |
| 821 |
// EXTERNAL MODULE: external {"this":["wp","editor"]} |
| 822 |
var external_this_wp_editor_ = __webpack_require__(2); |
| 823 |
;// ./node_modules/@wpsyntex/polylang-react-library/build/hooks/use-current-language.js |
| 824 |
/** |
| 825 |
* WordPress dependencies |
| 826 |
*/ |
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
/** |
| 831 |
* Custom hook to get the current language from the editor. |
| 832 |
* |
| 833 |
* @param {Array} languages The languages list. |
| 834 |
* @return {Object|null} The current language, `null` if not found. |
| 835 |
*/ |
| 836 |
const useCurrentLanguage = languages => { |
| 837 |
const currentPost = (0,external_this_wp_data_.useSelect)(select => select(external_this_wp_editor_.store).getCurrentPost()); |
| 838 |
if (!languages || !currentPost) { |
| 839 |
return null; |
| 840 |
} |
| 841 |
const currentLanguageSlug = currentPost.lang ?? pllEditorCurrentLanguageSlug; |
| 842 |
const currentLanguage = languages.find(language => { |
| 843 |
return language.slug === currentLanguageSlug; |
| 844 |
}); |
| 845 |
return currentLanguage ? currentLanguage : null; |
| 846 |
}; |
| 847 |
;// ./js/src/blocks/navigation-language-switcher/components/navigation-switcher-container.js |
| 848 |
/** |
| 849 |
* WordPress dependencies |
| 850 |
*/ |
| 851 |
|
| 852 |
|
| 853 |
/** |
| 854 |
* Internal dependencies |
| 855 |
*/ |
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
/** |
| 861 |
* Switcher container component. |
| 862 |
* |
| 863 |
* @param {Object} props The component props. |
| 864 |
* @param {Object} props.attributes The block attributes. |
| 865 |
* @param {Object} props.context The block context. |
| 866 |
* @return {ReactElement} The Switcher component. |
| 867 |
*/ |
| 868 |
|
| 869 |
const NavigationSwitcherContainer = ({ |
| 870 |
attributes, |
| 871 |
context |
| 872 |
}) => { |
| 873 |
const { |
| 874 |
dropdown, |
| 875 |
show_flags, |
| 876 |
show_names |
| 877 |
} = attributes; |
| 878 |
const { |
| 879 |
showSubmenuIcon, |
| 880 |
openSubmenusOnClick |
| 881 |
} = context; |
| 882 |
const { |
| 883 |
languages |
| 884 |
} = (0,external_this_wp_element_.useContext)(LanguagesContext); |
| 885 |
const currentLanguage = useCurrentLanguage(languages); |
| 886 |
const curatedLanguages = useCuratedLanguages(languages, currentLanguage, dropdown); |
| 887 |
return /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(switcher_ui_SwitcherUI, { |
| 888 |
languages: curatedLanguages, |
| 889 |
showFlags: Boolean(show_flags), |
| 890 |
showNames: Boolean(show_names), |
| 891 |
withSubmenuIcon: Boolean((showSubmenuIcon || openSubmenusOnClick) && dropdown) |
| 892 |
}); |
| 893 |
}; |
| 894 |
;// ./js/src/blocks/navigation-language-switcher/edit.js |
| 895 |
/** |
| 896 |
* Edit callback for navigation language switcher block. |
| 897 |
*/ |
| 898 |
|
| 899 |
/** |
| 900 |
* WordPress dependencies |
| 901 |
*/ |
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
/** |
| 907 |
* Internal dependencies |
| 908 |
*/ |
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
/** |
| 915 |
* Edit callback for navigation language switcher block. |
| 916 |
* |
| 917 |
* @param {Object} props Block properties. |
| 918 |
* @return {ReactElement} The block content and controls. |
| 919 |
*/ |
| 920 |
|
| 921 |
const edit_Edit = props => { |
| 922 |
const { |
| 923 |
dropdown |
| 924 |
} = props.attributes; |
| 925 |
const languages = useLanguagesList(); |
| 926 |
const { |
| 927 |
ToggleControlDropdown, |
| 928 |
ToggleControlShowNames, |
| 929 |
ToggleControlShowFlags, |
| 930 |
ToggleControlForceHome, |
| 931 |
ToggleControlHideCurrent, |
| 932 |
ToggleControlHideIfNoTranslations |
| 933 |
} = createLanguageSwitcherEdit(props); |
| 934 |
return /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsxs)("div", { |
| 935 |
...(0,external_this_wp_blockEditor_.useBlockProps)(), |
| 936 |
children: [/*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(external_this_wp_blockEditor_.InspectorControls, { |
| 937 |
children: /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsxs)(external_this_wp_components_.PanelBody, { |
| 938 |
title: (0,external_this_wp_i18n_.__)('Language switcher settings', 'polylang'), |
| 939 |
children: [/*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(ToggleControlDropdown, {}), /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(ToggleControlShowNames, {}), /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(ToggleControlShowFlags, {}), /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(ToggleControlForceHome, {}), !dropdown && /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(ToggleControlHideCurrent, {}), /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(ToggleControlHideIfNoTranslations, {})] |
| 940 |
}) |
| 941 |
}), /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(external_this_wp_components_.Disabled, { |
| 942 |
children: /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(LanguagesContext.Provider, { |
| 943 |
value: { |
| 944 |
languages |
| 945 |
}, |
| 946 |
children: /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(NavigationSwitcherContainer, { |
| 947 |
attributes: props.attributes, |
| 948 |
context: props.context |
| 949 |
}) |
| 950 |
}) |
| 951 |
})] |
| 952 |
}); |
| 953 |
}; |
| 954 |
;// ./src/modules/Blocks/Language_Switcher/Navigation/block.json |
| 955 |
const Navigation_block_namespaceObject = /*#__PURE__*/JSON.parse('{"UU":"polylang/navigation-language-switcher"}'); |
| 956 |
;// ./js/src/blocks/navigation-language-switcher/menu-items-converter.js |
| 957 |
/** |
| 958 |
* Menu items converter |
| 959 |
*/ |
| 960 |
|
| 961 |
/** |
| 962 |
* WordPress dependencies |
| 963 |
*/ |
| 964 |
|
| 965 |
|
| 966 |
/** |
| 967 |
* Internal dependencies |
| 968 |
*/ |
| 969 |
|
| 970 |
|
| 971 |
/** |
| 972 |
* Apply a callback function on each block of the blocks list. |
| 973 |
* |
| 974 |
* @param {Array} blocks The list of blocks to process. |
| 975 |
* @param {Array} menuItems The initial menu items from where the blocks are converted to. |
| 976 |
* @param {Object} blocksMapping The mapping between the menu items and their corresponding blocks. |
| 977 |
* @param {mapper} mapper A callback to change the converted block by another one if necessary |
| 978 |
* @return {Array} Array of blocks updated. |
| 979 |
*/ |
| 980 |
function mapBlockTree(blocks, menuItems, blocksMapping, mapper) { |
| 981 |
/** |
| 982 |
* A function to apply to each block to convert it if necessary by applying the `mapper` filter. |
| 983 |
* |
| 984 |
* @param {Object} block The block to replace or not. |
| 985 |
* @return {Object} The new block potentially replaced by the `mapper`. |
| 986 |
*/ |
| 987 |
const convertBlock = block => ({ |
| 988 |
...mapper(block, menuItems, blocksMapping), |
| 989 |
innerBlocks: mapBlockTree(block.innerBlocks, menuItems, blocksMapping, mapper) |
| 990 |
}); |
| 991 |
return blocks.map(convertBlock); |
| 992 |
} |
| 993 |
|
| 994 |
/** |
| 995 |
* A filter to detect the `core/navigation-link` block not correctly converted from the language switcher menu item |
| 996 |
* and convert it to its corresponding `polylang/navigation-language-switcher` block. |
| 997 |
* |
| 998 |
* @callback mapper |
| 999 |
* @param {Object} block The block converted from the menu item. |
| 1000 |
* @param {Array} menuItems The initial menu items from where the blocks are converted to. |
| 1001 |
* @param {Object} blocksMapping The mapping between the menu items and their corresponding blocks. |
| 1002 |
* @return {Object} The block correctly converted. |
| 1003 |
*/ |
| 1004 |
const blocksFilter = (block, menuItems, blocksMapping) => { |
| 1005 |
if (block.name === 'core/navigation-link' && block.attributes?.url === '#pll_switcher') { |
| 1006 |
const menuItem = menuItems.find(item => item.url === '#pll_switcher'); // Get the corresponding menu item. |
| 1007 |
const attributes = menuItem.meta._pll_menu_item; // Get its options. |
| 1008 |
const newBlock = (0,external_this_wp_blocks_.createBlock)(Navigation_block_namespaceObject.UU, attributes); |
| 1009 |
blocksMapping[menuItem.id] = newBlock.clientId; // Update the blocks mapping. |
| 1010 |
return newBlock; |
| 1011 |
} |
| 1012 |
return block; |
| 1013 |
}; |
| 1014 |
|
| 1015 |
/** |
| 1016 |
* A filter callback hooked to `blocks.navigation.__unstableMenuItemsToBlocks`. |
| 1017 |
* |
| 1018 |
* @param {Array} blocks The list of blocks to process. |
| 1019 |
* @param {Array} menuItems The initial menu items from where the blocks are converted to. |
| 1020 |
* @return {Array} Array of blocks updated. |
| 1021 |
*/ |
| 1022 |
const menuItemsToBlocksFilter = (blocks, menuItems) => ({ |
| 1023 |
...blocks, |
| 1024 |
innerBlocks: mapBlockTree(blocks.innerBlocks, menuItems, blocks.mapping, blocksFilter) |
| 1025 |
}); |
| 1026 |
;// ./js/src/blocks/navigation-language-switcher/index.js |
| 1027 |
/** |
| 1028 |
* Register navigation language switcher block. |
| 1029 |
*/ |
| 1030 |
|
| 1031 |
/** |
| 1032 |
* WordPress Dependencies |
| 1033 |
*/ |
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
/** |
| 1038 |
* Internal dependencies |
| 1039 |
*/ |
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
(0,external_this_wp_blocks_.registerBlockType)(Navigation_block_namespaceObject.UU, { |
| 1045 |
icon: icons_translation, |
| 1046 |
transforms: { |
| 1047 |
from: [{ |
| 1048 |
type: 'block', |
| 1049 |
blocks: ['core/navigation-link'], |
| 1050 |
transform: () => (0,external_this_wp_blocks_.createBlock)(Navigation_block_namespaceObject.UU) |
| 1051 |
}] |
| 1052 |
}, |
| 1053 |
edit: edit_Edit |
| 1054 |
}); |
| 1055 |
|
| 1056 |
/** |
| 1057 |
* Hooks to the classic menu conversion to core/navigation block to be able to convert |
| 1058 |
* the language switcher menu item to its corresponding block. |
| 1059 |
*/ |
| 1060 |
(0,external_this_wp_hooks_.addFilter)('blocks.navigation.__unstableMenuItemsToBlocks', 'polylang/include-language-switcher', menuItemsToBlocksFilter); |
| 1061 |
;// ./js/src/blocks/index.js |
| 1062 |
/** |
| 1063 |
* Registers Polylang blocks in the editors and enables attributes controls. |
| 1064 |
*/ |
| 1065 |
|
| 1066 |
|
| 1067 |
})(); |
| 1068 |
|
| 1069 |
this.polylang = __webpack_exports__; |
| 1070 |
/******/ })() |
| 1071 |
; |