| 1 |
/******/ (() => { // webpackBootstrap |
| 2 |
/******/ var __webpack_modules__ = ({ |
| 3 |
|
| 4 |
/***/ 677 |
| 5 |
(module) { |
| 6 |
|
| 7 |
module.exports = (function() { return this["React"]; }()); |
| 8 |
|
| 9 |
/***/ }, |
| 10 |
|
| 11 |
/***/ 631 |
| 12 |
(module) { |
| 13 |
|
| 14 |
module.exports = (function() { return this["wp"]["apiFetch"]; }()); |
| 15 |
|
| 16 |
/***/ }, |
| 17 |
|
| 18 |
/***/ 89 |
| 19 |
(module) { |
| 20 |
|
| 21 |
module.exports = (function() { return this["wp"]["blockEditor"]; }()); |
| 22 |
|
| 23 |
/***/ }, |
| 24 |
|
| 25 |
/***/ 545 |
| 26 |
(module) { |
| 27 |
|
| 28 |
module.exports = (function() { return this["wp"]["blocks"]; }()); |
| 29 |
|
| 30 |
/***/ }, |
| 31 |
|
| 32 |
/***/ 959 |
| 33 |
(module) { |
| 34 |
|
| 35 |
module.exports = (function() { return this["wp"]["components"]; }()); |
| 36 |
|
| 37 |
/***/ }, |
| 38 |
|
| 39 |
/***/ 987 |
| 40 |
(module) { |
| 41 |
|
| 42 |
module.exports = (function() { return this["wp"]["data"]; }()); |
| 43 |
|
| 44 |
/***/ }, |
| 45 |
|
| 46 |
/***/ 2 |
| 47 |
(module) { |
| 48 |
|
| 49 |
module.exports = (function() { return this["wp"]["editor"]; }()); |
| 50 |
|
| 51 |
/***/ }, |
| 52 |
|
| 53 |
/***/ 601 |
| 54 |
(module) { |
| 55 |
|
| 56 |
module.exports = (function() { return this["wp"]["element"]; }()); |
| 57 |
|
| 58 |
/***/ }, |
| 59 |
|
| 60 |
/***/ 873 |
| 61 |
(module) { |
| 62 |
|
| 63 |
module.exports = (function() { return this["wp"]["hooks"]; }()); |
| 64 |
|
| 65 |
/***/ }, |
| 66 |
|
| 67 |
/***/ 75 |
| 68 |
(module) { |
| 69 |
|
| 70 |
module.exports = (function() { return this["wp"]["i18n"]; }()); |
| 71 |
|
| 72 |
/***/ }, |
| 73 |
|
| 74 |
/***/ 672 |
| 75 |
(module) { |
| 76 |
|
| 77 |
module.exports = (function() { return this["wp"]["notices"]; }()); |
| 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 |
;// ./js/src/blocks/language-switcher/deprecated.js |
| 222 |
/** |
| 223 |
* Deprecated language switcher block. |
| 224 |
*/ |
| 225 |
|
| 226 |
const V2Attributes = { |
| 227 |
layout: 'vertical', |
| 228 |
show_labels: 'names', |
| 229 |
show_flags: false, |
| 230 |
force_home: false, |
| 231 |
hide_current: false, |
| 232 |
hide_if_no_translation: false, |
| 233 |
flag_aspect_ratio: '3:2', |
| 234 |
flag_border_radius: 0, |
| 235 |
flag_width: '18px', |
| 236 |
flag_label_spacing: '0.3em', |
| 237 |
className: '' |
| 238 |
}; |
| 239 |
const v1 = { |
| 240 |
attributes: { |
| 241 |
dropdown: { |
| 242 |
type: 'boolean', |
| 243 |
default: false |
| 244 |
}, |
| 245 |
show_names: { |
| 246 |
type: 'boolean', |
| 247 |
default: true |
| 248 |
}, |
| 249 |
show_flags: { |
| 250 |
type: 'boolean', |
| 251 |
default: false |
| 252 |
}, |
| 253 |
force_home: { |
| 254 |
type: 'boolean', |
| 255 |
default: false |
| 256 |
}, |
| 257 |
hide_current: { |
| 258 |
type: 'boolean', |
| 259 |
default: false |
| 260 |
}, |
| 261 |
hide_if_no_translation: { |
| 262 |
type: 'boolean', |
| 263 |
default: false |
| 264 |
}, |
| 265 |
className: { |
| 266 |
type: 'string', |
| 267 |
default: '' |
| 268 |
} |
| 269 |
}, |
| 270 |
isEligible: attributes => 'dropdown' in attributes || 'show_names' in attributes, |
| 271 |
migrate(attributes) { |
| 272 |
const { |
| 273 |
dropdown, |
| 274 |
show_names, |
| 275 |
show_flags, |
| 276 |
force_home, |
| 277 |
hide_current, |
| 278 |
hide_if_no_translation, |
| 279 |
className |
| 280 |
} = attributes; |
| 281 |
return { |
| 282 |
...V2Attributes, |
| 283 |
layout: dropdown ? 'select' : 'vertical', |
| 284 |
show_labels: show_names ? 'names' : '', |
| 285 |
show_flags: show_names ? show_flags : true, |
| 286 |
force_home, |
| 287 |
hide_current, |
| 288 |
hide_if_no_translation, |
| 289 |
className: className || '' |
| 290 |
}; |
| 291 |
} |
| 292 |
}; |
| 293 |
/* harmony default export */ const deprecated = ([v1]); |
| 294 |
// EXTERNAL MODULE: external {"this":["wp","blockEditor"]} |
| 295 |
var external_this_wp_blockEditor_ = __webpack_require__(89); |
| 296 |
// EXTERNAL MODULE: external {"this":["wp","components"]} |
| 297 |
var external_this_wp_components_ = __webpack_require__(959); |
| 298 |
// EXTERNAL MODULE: external {"this":["wp","apiFetch"]} |
| 299 |
var external_this_wp_apiFetch_ = __webpack_require__(631); |
| 300 |
var external_this_wp_apiFetch_default = /*#__PURE__*/__webpack_require__.n(external_this_wp_apiFetch_); |
| 301 |
// EXTERNAL MODULE: external {"this":["wp","element"]} |
| 302 |
var external_this_wp_element_ = __webpack_require__(601); |
| 303 |
;// ./node_modules/@wpsyntex/polylang-react-library/build/hooks/use-languages-list.js |
| 304 |
/** |
| 305 |
* WordPress dependencies |
| 306 |
*/ |
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
/** |
| 311 |
* Custom hook to get the languages list. |
| 312 |
* |
| 313 |
* @return {Array|null} The languages list, `null` if not loaded yet. |
| 314 |
*/ |
| 315 |
const useLanguagesList = () => { |
| 316 |
const [languages, setLanguages] = (0,external_this_wp_element_.useState)(null); |
| 317 |
(0,external_this_wp_element_.useEffect)(() => { |
| 318 |
external_this_wp_apiFetch_default()({ |
| 319 |
path: '/pll/v1/languages', |
| 320 |
method: 'GET' |
| 321 |
}).then(response => setLanguages(response)); |
| 322 |
}, []); |
| 323 |
return languages; |
| 324 |
}; |
| 325 |
;// ./node_modules/@wpsyntex/polylang-react-library/build/hooks/use-curated-languages.js |
| 326 |
/** |
| 327 |
* WordPress dependencies |
| 328 |
*/ |
| 329 |
|
| 330 |
|
| 331 |
/** |
| 332 |
* Hook to curate the languages. |
| 333 |
* Returns an array of languages ensuring that the current language is always the first one. |
| 334 |
* |
| 335 |
* @param {Object[]} languages The languages. |
| 336 |
* @param {Object} currentLanguage The current language. |
| 337 |
* @param {boolean} reduceToOneItem Whether to reduce the languages to one item. |
| 338 |
* @return {Object[]} The curated languages. |
| 339 |
*/ |
| 340 |
const useCuratedLanguages = (languages, currentLanguage, reduceToOneItem) => { |
| 341 |
const curatedLanguages = (0,external_this_wp_element_.useMemo)(() => { |
| 342 |
if (!currentLanguage) { |
| 343 |
return []; |
| 344 |
} |
| 345 |
if (reduceToOneItem) { |
| 346 |
return [currentLanguage]; |
| 347 |
} |
| 348 |
return [currentLanguage, ...languages.filter(language => { |
| 349 |
return language.slug !== currentLanguage.slug; |
| 350 |
})]; |
| 351 |
}, [languages, currentLanguage, reduceToOneItem]); |
| 352 |
return curatedLanguages; |
| 353 |
}; |
| 354 |
;// ./node_modules/@wpsyntex/polylang-react-library/build/icons/submenu.js |
| 355 |
/** |
| 356 |
* Submenu icon |
| 357 |
*/ |
| 358 |
|
| 359 |
/** |
| 360 |
* WordPress dependencies |
| 361 |
*/ |
| 362 |
|
| 363 |
|
| 364 |
const submenu_isPrimitivesComponents = 'undefined' !== typeof wp.primitives; |
| 365 |
const SubmenuIcon = () => submenu_isPrimitivesComponents ? /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(external_this_wp_primitives_.SVG, { |
| 366 |
xmlns: "http://www.w3.org/2000/svg", |
| 367 |
width: "12", |
| 368 |
height: "12", |
| 369 |
viewBox: "0 0 12 12", |
| 370 |
fill: "none", |
| 371 |
children: /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(external_this_wp_primitives_.Path, { |
| 372 |
d: "M1.50002 4L6.00002 8L10.5 4", |
| 373 |
strokeWidth: "1.5" |
| 374 |
}) |
| 375 |
}) : 'submenu'; |
| 376 |
/* harmony default export */ const submenu = (SubmenuIcon); |
| 377 |
;// ./js/src/blocks/components/switcher-link-element.js |
| 378 |
|
| 379 |
/** |
| 380 |
* Switcher link element component. |
| 381 |
* |
| 382 |
* @param {Object} props Component props. |
| 383 |
* @param {ReactElement} props.flag Flag to display. |
| 384 |
* @param {string} props.label Label to display. |
| 385 |
* @param {string} props.labelSpacing CSS length for the space between flag and label. |
| 386 |
* @return {ReactElement} The Switcher element component. |
| 387 |
*/ |
| 388 |
const SwitcherLinkElement = ({ |
| 389 |
flag, |
| 390 |
label, |
| 391 |
labelSpacing |
| 392 |
}) => { |
| 393 |
const hasLabel = '' !== label; |
| 394 |
const labelStyle = hasLabel && labelSpacing ? { |
| 395 |
'--pll-flag-label-spacing': labelSpacing |
| 396 |
} : undefined; |
| 397 |
return ( |
| 398 |
/*#__PURE__*/ |
| 399 |
// eslint-disable-next-line jsx-a11y/anchor-is-valid |
| 400 |
(0,react_jsx_runtime_production_min_namespaceFn().jsxs)("a", { |
| 401 |
href: '#', |
| 402 |
children: [flag, hasLabel && /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)("span", { |
| 403 |
className: "pll-switcher-label", |
| 404 |
style: labelStyle, |
| 405 |
children: label |
| 406 |
})] |
| 407 |
}) |
| 408 |
); |
| 409 |
}; |
| 410 |
;// ./js/src/blocks/components/switcher-utils.js |
| 411 |
/** |
| 412 |
* Returns the switcher wrapper class names. |
| 413 |
* |
| 414 |
* @param {string} layout The switcher layout. |
| 415 |
* @param {boolean} showFlags Whether flags are displayed. |
| 416 |
* @param {string} flagAspectRatio The flag aspect ratio. |
| 417 |
* @param {string} [alignment] The items alignment. Omitted when unset. |
| 418 |
* @return {string} The switcher class names. |
| 419 |
*/ |
| 420 |
const getSwitcherClassName = (layout, showFlags, flagAspectRatio, alignment) => { |
| 421 |
const classes = ['pll-switcher', `pll-layout-${layout}`]; |
| 422 |
if (alignment) { |
| 423 |
classes.push(`pll-alignment-${alignment}`); |
| 424 |
} |
| 425 |
if (showFlags) { |
| 426 |
classes.push(`pll-aspect-ratio-${flagAspectRatio.replace(':', '')}`); |
| 427 |
} |
| 428 |
return classes.join(' '); |
| 429 |
}; |
| 430 |
|
| 431 |
/** |
| 432 |
* Gets the label for a language. |
| 433 |
* |
| 434 |
* @param {Object} language The language object. |
| 435 |
* @param {string} showLabels Whether to show the names. Can be 'names', 'codes' or ''. |
| 436 |
* @return {string} The label for the language. |
| 437 |
*/ |
| 438 |
const getLabel = (language, showLabels) => { |
| 439 |
let label = ''; |
| 440 |
if (showLabels === 'names') { |
| 441 |
label = language.name; |
| 442 |
} else if (showLabels === 'codes') { |
| 443 |
label = language.slug.toUpperCase(); |
| 444 |
} |
| 445 |
return label; |
| 446 |
}; |
| 447 |
|
| 448 |
/** |
| 449 |
* Returns the CSS length for the space between flag and label. |
| 450 |
* |
| 451 |
* @param {string} showLabels Whether to show labels. Can be 'names', 'codes' or ''. |
| 452 |
* @param {string} flagLabelSpacing CSS length for the space between flag and label. |
| 453 |
* @return {string|undefined} The label spacing, or undefined when labels are hidden. |
| 454 |
*/ |
| 455 |
const getLabelSpacing = (showLabels, flagLabelSpacing) => { |
| 456 |
if ('' === showLabels) { |
| 457 |
return undefined; |
| 458 |
} |
| 459 |
return flagLabelSpacing; |
| 460 |
}; |
| 461 |
;// ./js/src/blocks/hooks/use-memoized-flag.js |
| 462 |
/** |
| 463 |
* WordPress dependencies |
| 464 |
*/ |
| 465 |
|
| 466 |
|
| 467 |
/** |
| 468 |
* Strips fixed dimensions from flag HTML markup. |
| 469 |
* |
| 470 |
* @param {string} html The flag HTML markup. |
| 471 |
* @return {string} The flag HTML without fixed dimensions. |
| 472 |
*/ |
| 473 |
|
| 474 |
const stripFlagDimensions = html => { |
| 475 |
return html.replace(/\s(?:width|height)=["'][^"']*["']/gi, '').replace(/\sstyle=["'][^"']*["']/gi, ''); |
| 476 |
}; |
| 477 |
|
| 478 |
/** |
| 479 |
* Returns a memoized flag element for a language. |
| 480 |
* |
| 481 |
* @param {Object} language The language object. |
| 482 |
* @param {boolean} showFlags Whether to show the flags. |
| 483 |
* @param {number} flagBorderRadius The border radius of the flags. |
| 484 |
* @param {string} flagWidth The width of the flags as a CSS length. |
| 485 |
* @return {ReactElement|null} The flag for the language. |
| 486 |
*/ |
| 487 |
const useMemoizedFlag = (language, showFlags, flagBorderRadius, flagWidth) => { |
| 488 |
return (0,external_this_wp_element_.useMemo)(() => { |
| 489 |
if (!showFlags || !language?.flag) { |
| 490 |
return null; |
| 491 |
} |
| 492 |
return /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)("span", { |
| 493 |
className: "pll-switcher-flag", |
| 494 |
style: { |
| 495 |
'--pll-flag-border-radius': flagBorderRadius, |
| 496 |
'--pll-flag-width': flagWidth |
| 497 |
}, |
| 498 |
dangerouslySetInnerHTML: { |
| 499 |
__html: stripFlagDimensions(language.flag) |
| 500 |
} |
| 501 |
}); |
| 502 |
}, [language?.flag, showFlags, flagBorderRadius, flagWidth]); |
| 503 |
}; |
| 504 |
;// ./js/src/blocks/components/switcher-language-link.js |
| 505 |
/** |
| 506 |
* Internal dependencies |
| 507 |
*/ |
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
/** |
| 513 |
* Renders a language link for the switcher preview. |
| 514 |
* |
| 515 |
* @param {Object} props Component props. |
| 516 |
* @param {Object} props.language The language object. |
| 517 |
* @param {string} props.showLabels Whether to show labels. Can be 'names', 'codes' or ''. |
| 518 |
* @param {boolean} props.showFlags Whether to show the flags. |
| 519 |
* @param {number} props.flagBorderRadius The border radius of the flags. |
| 520 |
* @param {string} props.flagWidth The width of the flags as a CSS length. |
| 521 |
* @param {string|undefined} props.labelSpacing CSS length for the space between flag and label. |
| 522 |
* @return {ReactElement} The language link element. |
| 523 |
*/ |
| 524 |
|
| 525 |
const SwitcherLanguageLink = ({ |
| 526 |
language, |
| 527 |
showLabels, |
| 528 |
showFlags, |
| 529 |
flagBorderRadius, |
| 530 |
flagWidth, |
| 531 |
labelSpacing |
| 532 |
}) => { |
| 533 |
const flag = useMemoizedFlag(language, showFlags, flagBorderRadius, flagWidth); |
| 534 |
return /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(SwitcherLinkElement, { |
| 535 |
label: getLabel(language, showLabels), |
| 536 |
flag: flag, |
| 537 |
labelSpacing: labelSpacing |
| 538 |
}); |
| 539 |
}; |
| 540 |
// EXTERNAL MODULE: external {"this":["wp","data"]} |
| 541 |
var external_this_wp_data_ = __webpack_require__(987); |
| 542 |
;// ./js/src/blocks/hooks/use-current-language-with-editor-context.js |
| 543 |
/** |
| 544 |
* WordPress dependencies |
| 545 |
*/ |
| 546 |
|
| 547 |
|
| 548 |
/** |
| 549 |
* Finds a language by slug. |
| 550 |
* |
| 551 |
* @param {Array} languages The languages list. |
| 552 |
* @param {string} slug The language slug. |
| 553 |
* @return {Object|null} The language, `null` if not found. |
| 554 |
*/ |
| 555 |
const findLanguageBySlug = (languages, slug) => { |
| 556 |
if (!languages || !slug) { |
| 557 |
return null; |
| 558 |
} |
| 559 |
const currentLanguage = languages.find(language => { |
| 560 |
return language.slug === slug; |
| 561 |
}); |
| 562 |
return currentLanguage ? currentLanguage : null; |
| 563 |
}; |
| 564 |
|
| 565 |
/** |
| 566 |
* Resolves the current language in block editor contexts. |
| 567 |
* |
| 568 |
* The widgets editor does not load `@wordpress/editor`, so the `core/editor` |
| 569 |
* store may be unavailable. In that context, fall back to the current language |
| 570 |
* slug injected by PHP (default language when none is set). |
| 571 |
* |
| 572 |
* @param {Array} languages The languages list. |
| 573 |
* @return {Object|null} The current language, `null` if not found. |
| 574 |
*/ |
| 575 |
const useCurrentLanguageWithEditorContext = languages => { |
| 576 |
return (0,external_this_wp_data_.useSelect)(select => { |
| 577 |
if (!languages) { |
| 578 |
return null; |
| 579 |
} |
| 580 |
const editorStore = select('core/editor'); |
| 581 |
if (!editorStore) { |
| 582 |
return findLanguageBySlug(languages, pllEditorCurrentLanguageSlug // eslint-disable-line no-undef |
| 583 |
); |
| 584 |
} |
| 585 |
const currentPost = editorStore.getCurrentPost(); |
| 586 |
if (!currentPost) { |
| 587 |
return null; |
| 588 |
} |
| 589 |
const currentLanguageSlug = currentPost.lang ?? pllEditorCurrentLanguageSlug; // eslint-disable-line no-undef |
| 590 |
|
| 591 |
return findLanguageBySlug(languages, currentLanguageSlug); |
| 592 |
}, [languages]); |
| 593 |
}; |
| 594 |
;// ./js/src/blocks/languages-context.js |
| 595 |
/** |
| 596 |
* WordPress dependencies. |
| 597 |
*/ |
| 598 |
|
| 599 |
|
| 600 |
/** |
| 601 |
* Context for the languages. |
| 602 |
* |
| 603 |
* @type {React.Context<null>} |
| 604 |
*/ |
| 605 |
const LanguagesContext = (0,external_this_wp_element_.createContext)(null); |
| 606 |
;// ./js/src/blocks/language-switcher/rendered-switcher.js |
| 607 |
/** |
| 608 |
* WordPress dependencies |
| 609 |
*/ |
| 610 |
|
| 611 |
|
| 612 |
/** |
| 613 |
* External dependencies |
| 614 |
*/ |
| 615 |
|
| 616 |
|
| 617 |
/** |
| 618 |
* Internal dependencies |
| 619 |
*/ |
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
/** |
| 626 |
* Rendered switcher component. |
| 627 |
* |
| 628 |
* @param {Object} props The component props. |
| 629 |
* @param {Object} props.attributes The block attributes. |
| 630 |
* @return {ReactElement} The rendered switcher. |
| 631 |
*/ |
| 632 |
|
| 633 |
const RenderedSwitcher = ({ |
| 634 |
attributes |
| 635 |
}) => { |
| 636 |
const { |
| 637 |
layout, |
| 638 |
show_labels, |
| 639 |
show_flags, |
| 640 |
flag_aspect_ratio, |
| 641 |
flag_border_radius, |
| 642 |
flag_width, |
| 643 |
flag_label_spacing, |
| 644 |
style |
| 645 |
} = attributes; |
| 646 |
const { |
| 647 |
languages |
| 648 |
} = (0,external_this_wp_element_.useContext)(LanguagesContext); |
| 649 |
const currentLanguage = useCurrentLanguageWithEditorContext(languages); |
| 650 |
const curatedLanguages = useCuratedLanguages(languages, currentLanguage, false); |
| 651 |
const alignment = style?.typography?.textAlign; |
| 652 |
const switcherClassName = getSwitcherClassName(layout, show_flags, flag_aspect_ratio, alignment); |
| 653 |
const labelSpacing = getLabelSpacing(show_labels, flag_label_spacing); |
| 654 |
const linkProps = { |
| 655 |
showLabels: show_labels, |
| 656 |
showFlags: show_flags, |
| 657 |
flagBorderRadius: flag_border_radius, |
| 658 |
flagWidth: flag_width, |
| 659 |
labelSpacing |
| 660 |
}; |
| 661 |
if (layout === 'dropdown') { |
| 662 |
const currentLanguageItem = curatedLanguages[0]; |
| 663 |
return /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)("nav", { |
| 664 |
className: switcherClassName, |
| 665 |
children: /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsxs)("div", { |
| 666 |
className: "pll-switcher-inner", |
| 667 |
children: [currentLanguageItem && /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(SwitcherLanguageLink, { |
| 668 |
language: currentLanguageItem, |
| 669 |
...linkProps |
| 670 |
}), /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)("button", { |
| 671 |
className: "pll-submenu-toggle", |
| 672 |
children: /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(submenu, {}) |
| 673 |
})] |
| 674 |
}) |
| 675 |
}); |
| 676 |
} |
| 677 |
if (layout === 'select') { |
| 678 |
return /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)("div", { |
| 679 |
className: switcherClassName, |
| 680 |
children: /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)("select", { |
| 681 |
className: "pll-switcher-select", |
| 682 |
children: curatedLanguages.map(language => { |
| 683 |
return /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)("option", { |
| 684 |
value: language.slug, |
| 685 |
children: getLabel(language, show_labels) |
| 686 |
}, language.slug); |
| 687 |
}) |
| 688 |
}) |
| 689 |
}); |
| 690 |
} |
| 691 |
return /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)("nav", { |
| 692 |
className: switcherClassName, |
| 693 |
children: /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)("ul", { |
| 694 |
children: curatedLanguages.map(language => { |
| 695 |
return /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)("li", { |
| 696 |
children: /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(SwitcherLanguageLink, { |
| 697 |
language: language, |
| 698 |
...linkProps |
| 699 |
}) |
| 700 |
}, language.slug); |
| 701 |
}) |
| 702 |
}) |
| 703 |
}); |
| 704 |
}; |
| 705 |
// EXTERNAL MODULE: external {"this":["wp","i18n"]} |
| 706 |
var external_this_wp_i18n_ = __webpack_require__(75); |
| 707 |
// EXTERNAL MODULE: external {"this":["wp","notices"]} |
| 708 |
var external_this_wp_notices_ = __webpack_require__(672); |
| 709 |
;// ./js/src/blocks/components/switcher-controls.js |
| 710 |
/** |
| 711 |
* WordPress dependencies |
| 712 |
*/ |
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
const CSS_LENGTH_UNITS = [{ |
| 720 |
value: 'px', |
| 721 |
label: 'px' |
| 722 |
}, { |
| 723 |
value: 'em', |
| 724 |
label: 'em' |
| 725 |
}, { |
| 726 |
value: 'rem', |
| 727 |
label: 'rem' |
| 728 |
}, { |
| 729 |
value: 'vh', |
| 730 |
label: 'vh' |
| 731 |
}, { |
| 732 |
value: 'vw', |
| 733 |
label: 'vw' |
| 734 |
}]; |
| 735 |
const LABEL_SPACING_DEFAULT_VALUE = '0.3em'; |
| 736 |
const ALL_LAYOUT_OPTIONS = [{ |
| 737 |
label: (0,external_this_wp_i18n_._x)('Horizontal', 'layout', 'polylang'), |
| 738 |
value: 'horizontal' |
| 739 |
}, { |
| 740 |
label: (0,external_this_wp_i18n_._x)('Vertical', 'layout', 'polylang'), |
| 741 |
value: 'vertical' |
| 742 |
}, { |
| 743 |
label: (0,external_this_wp_i18n_.__)('Dropdown', 'polylang'), |
| 744 |
value: 'dropdown' |
| 745 |
}, { |
| 746 |
label: (0,external_this_wp_i18n_.__)('Selector', 'polylang'), |
| 747 |
value: 'select' |
| 748 |
}]; |
| 749 |
const ALL_LAYOUT_TOOLBAR_CONTROLS = [{ |
| 750 |
title: (0,external_this_wp_i18n_._x)('Horizontal', 'layout', 'polylang'), |
| 751 |
layout: 'horizontal' |
| 752 |
}, { |
| 753 |
title: (0,external_this_wp_i18n_._x)('Vertical', 'layout', 'polylang'), |
| 754 |
layout: 'vertical' |
| 755 |
}, { |
| 756 |
title: (0,external_this_wp_i18n_.__)('Dropdown', 'polylang'), |
| 757 |
layout: 'dropdown' |
| 758 |
}]; |
| 759 |
|
| 760 |
/** |
| 761 |
* Switcher controls component for toolbar and inspector controls. |
| 762 |
* |
| 763 |
* @param {Object} props The component props. |
| 764 |
* @param {Object} props.attributes The block attributes. |
| 765 |
* @param {Function} props.setAttributes The function to set the block attributes. |
| 766 |
* @param {Array<string>} props.layoutOptions Optional layout values to expose. |
| 767 |
* @return {React.ReactNode} The switcher controls component. |
| 768 |
*/ |
| 769 |
const SwitcherControls = ({ |
| 770 |
attributes, |
| 771 |
setAttributes, |
| 772 |
layoutOptions = ['horizontal', 'vertical', 'dropdown', 'select'] |
| 773 |
}) => { |
| 774 |
const { |
| 775 |
layout, |
| 776 |
show_labels, |
| 777 |
show_flags, |
| 778 |
force_home, |
| 779 |
hide_current, |
| 780 |
flag_aspect_ratio, |
| 781 |
flag_border_radius, |
| 782 |
flag_width, |
| 783 |
flag_label_spacing, |
| 784 |
hide_if_no_translation |
| 785 |
} = attributes; |
| 786 |
const { |
| 787 |
createWarningNotice |
| 788 |
} = (0,external_this_wp_data_.useDispatch)(external_this_wp_notices_.store); |
| 789 |
const layoutSelectOptions = ALL_LAYOUT_OPTIONS.filter(option => layoutOptions.includes(option.value)); |
| 790 |
const layoutToolbarControls = ALL_LAYOUT_TOOLBAR_CONTROLS.filter(control => layoutOptions.includes(control.layout)).map(control => ({ |
| 791 |
title: control.title, |
| 792 |
onClick: () => setAttributes({ |
| 793 |
layout: control.layout |
| 794 |
}) |
| 795 |
})); |
| 796 |
const labelOptions = [{ |
| 797 |
label: (0,external_this_wp_i18n_.__)('Language names', 'polylang'), |
| 798 |
value: 'names' |
| 799 |
}, { |
| 800 |
label: (0,external_this_wp_i18n_.__)('Language codes', 'polylang'), |
| 801 |
value: 'codes' |
| 802 |
}]; |
| 803 |
if (show_flags) { |
| 804 |
labelOptions.push({ |
| 805 |
label: (0,external_this_wp_i18n_._x)('None', 'Labels', 'polylang'), |
| 806 |
value: '' |
| 807 |
}); |
| 808 |
} |
| 809 |
const toolbarLabelControls = [{ |
| 810 |
title: (0,external_this_wp_i18n_.__)('Language names', 'polylang'), |
| 811 |
onClick: () => setAttributes({ |
| 812 |
show_labels: 'names' |
| 813 |
}) |
| 814 |
}, { |
| 815 |
title: (0,external_this_wp_i18n_.__)('Language codes', 'polylang'), |
| 816 |
onClick: () => setAttributes({ |
| 817 |
show_labels: 'codes' |
| 818 |
}) |
| 819 |
}]; |
| 820 |
if (show_flags) { |
| 821 |
toolbarLabelControls.push({ |
| 822 |
title: (0,external_this_wp_i18n_._x)('None', 'Labels', 'polylang'), |
| 823 |
onClick: () => { |
| 824 |
if (!show_flags) { |
| 825 |
createWarningNotice((0,external_this_wp_i18n_.__)('Labels cannot be hidden if flags are not shown.', 'polylang')); |
| 826 |
return; |
| 827 |
} |
| 828 |
setAttributes({ |
| 829 |
show_labels: '', |
| 830 |
flag_label_spacing: LABEL_SPACING_DEFAULT_VALUE |
| 831 |
}); |
| 832 |
} |
| 833 |
}); |
| 834 |
} |
| 835 |
return /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsxs)((react_jsx_runtime_production_min_namespaceFn().Fragment), { |
| 836 |
children: [/*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsxs)(external_this_wp_blockEditor_.InspectorControls, { |
| 837 |
children: [/*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsxs)(external_this_wp_components_.PanelBody, { |
| 838 |
title: (0,external_this_wp_i18n_.__)('Display', 'polylang'), |
| 839 |
children: [/*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(external_this_wp_components_.SelectControl, { |
| 840 |
label: (0,external_this_wp_i18n_.__)('Layout', 'polylang'), |
| 841 |
value: layout, |
| 842 |
options: layoutSelectOptions, |
| 843 |
onChange: value => { |
| 844 |
setAttributes({ |
| 845 |
layout: value |
| 846 |
}); |
| 847 |
if ('select' === value) { |
| 848 |
setAttributes({ |
| 849 |
show_flags: false |
| 850 |
}); |
| 851 |
if ('' === show_labels) { |
| 852 |
setAttributes({ |
| 853 |
show_labels: 'names' |
| 854 |
}); |
| 855 |
} |
| 856 |
} |
| 857 |
}, |
| 858 |
__next40pxDefaultSize: true |
| 859 |
}), 'select' !== layout && /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(external_this_wp_components_.SelectControl, { |
| 860 |
label: (0,external_this_wp_i18n_.__)('Labels', 'polylang'), |
| 861 |
value: show_labels, |
| 862 |
options: labelOptions, |
| 863 |
onChange: value => { |
| 864 |
if ('' === value) { |
| 865 |
if (!show_flags) { |
| 866 |
createWarningNotice((0,external_this_wp_i18n_.__)('Labels cannot be hidden if flags are not shown.', 'polylang')); |
| 867 |
return; |
| 868 |
} |
| 869 |
setAttributes({ |
| 870 |
show_labels: value, |
| 871 |
flag_label_spacing: LABEL_SPACING_DEFAULT_VALUE |
| 872 |
}); |
| 873 |
return; |
| 874 |
} |
| 875 |
setAttributes({ |
| 876 |
show_labels: value |
| 877 |
}); |
| 878 |
}, |
| 879 |
__next40pxDefaultSize: true |
| 880 |
})] |
| 881 |
}), 'select' !== layout && /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsxs)(external_this_wp_components_.PanelBody, { |
| 882 |
title: (0,external_this_wp_i18n_.__)('Flags Settings', 'polylang'), |
| 883 |
children: [/*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(external_this_wp_components_.ToggleControl, { |
| 884 |
label: (0,external_this_wp_i18n_.__)('Display flags', 'polylang'), |
| 885 |
checked: show_flags, |
| 886 |
onChange: value => { |
| 887 |
if ('' === show_labels && !value) { |
| 888 |
createWarningNotice((0,external_this_wp_i18n_.__)('Flags cannot be hidden if labels are not displayed.', 'polylang')); |
| 889 |
return; |
| 890 |
} |
| 891 |
setAttributes({ |
| 892 |
show_flags: value |
| 893 |
}); |
| 894 |
} |
| 895 |
}), show_flags && /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsxs)((react_jsx_runtime_production_min_namespaceFn().Fragment), { |
| 896 |
children: [/*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(external_this_wp_components_.RadioControl, { |
| 897 |
label: (0,external_this_wp_i18n_.__)('Aspect', 'polylang'), |
| 898 |
selected: flag_aspect_ratio, |
| 899 |
options: [{ |
| 900 |
label: (0,external_this_wp_i18n_.__)('Landscape (3:2)', 'polylang'), |
| 901 |
value: '3:2' |
| 902 |
}, { |
| 903 |
label: (0,external_this_wp_i18n_.__)('Square (1:1)', 'polylang'), |
| 904 |
value: '1:1' |
| 905 |
}], |
| 906 |
onChange: value => setAttributes({ |
| 907 |
flag_aspect_ratio: value |
| 908 |
}) |
| 909 |
}), /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(external_this_wp_components_.RangeControl, { |
| 910 |
label: (0,external_this_wp_i18n_.__)('Border radius', 'polylang'), |
| 911 |
initialPosition: 0, |
| 912 |
value: flag_border_radius, |
| 913 |
min: 0, |
| 914 |
max: 100, |
| 915 |
step: 1, |
| 916 |
allowReset: true, |
| 917 |
resetFallbackValue: 0, |
| 918 |
onChange: value => setAttributes({ |
| 919 |
flag_border_radius: value |
| 920 |
}), |
| 921 |
__next40pxDefaultSize: true |
| 922 |
}), /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(external_this_wp_components_.__experimentalUnitControl, { |
| 923 |
__next40pxDefaultSize: true, |
| 924 |
label: (0,external_this_wp_i18n_.__)('Size', 'polylang'), |
| 925 |
value: flag_width, |
| 926 |
units: CSS_LENGTH_UNITS, |
| 927 |
onChange: value => setAttributes({ |
| 928 |
flag_width: value |
| 929 |
}) |
| 930 |
}), '' !== show_labels && /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(external_this_wp_components_.__experimentalUnitControl, { |
| 931 |
__next40pxDefaultSize: true, |
| 932 |
label: (0,external_this_wp_i18n_.__)('Label spacing', 'polylang'), |
| 933 |
value: flag_label_spacing, |
| 934 |
units: CSS_LENGTH_UNITS, |
| 935 |
onChange: value => setAttributes({ |
| 936 |
flag_label_spacing: value |
| 937 |
}) |
| 938 |
})] |
| 939 |
})] |
| 940 |
}), /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsxs)(external_this_wp_components_.PanelBody, { |
| 941 |
title: (0,external_this_wp_i18n_.__)('Behavior', 'polylang'), |
| 942 |
children: [/*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(external_this_wp_components_.ToggleControl, { |
| 943 |
label: (0,external_this_wp_i18n_.__)('Force link to front page', 'polylang'), |
| 944 |
checked: force_home, |
| 945 |
onChange: value => setAttributes({ |
| 946 |
force_home: value |
| 947 |
}) |
| 948 |
}), /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(external_this_wp_components_.ToggleControl, { |
| 949 |
label: (0,external_this_wp_i18n_.__)('Hide the current language', 'polylang'), |
| 950 |
checked: hide_current, |
| 951 |
onChange: value => setAttributes({ |
| 952 |
hide_current: value |
| 953 |
}) |
| 954 |
}), /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(external_this_wp_components_.ToggleControl, { |
| 955 |
label: (0,external_this_wp_i18n_.__)('Hide languages with no translation', 'polylang'), |
| 956 |
checked: hide_if_no_translation, |
| 957 |
onChange: value => setAttributes({ |
| 958 |
hide_if_no_translation: value |
| 959 |
}) |
| 960 |
})] |
| 961 |
})] |
| 962 |
}), /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(external_this_wp_blockEditor_.BlockControls, { |
| 963 |
children: /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsxs)(external_this_wp_components_.ToolbarGroup, { |
| 964 |
children: [/*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(external_this_wp_components_.ToolbarDropdownMenu, { |
| 965 |
label: (0,external_this_wp_i18n_.__)('Layout', 'polylang'), |
| 966 |
controls: layoutToolbarControls |
| 967 |
}), 'select' !== layout && /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(external_this_wp_components_.ToolbarButton, { |
| 968 |
icon: /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)("span", { |
| 969 |
className: "dashicons dashicons-flag" |
| 970 |
}), |
| 971 |
label: show_flags ? (0,external_this_wp_i18n_.__)('Hide flags', 'polylang') : (0,external_this_wp_i18n_.__)('Display flags', 'polylang'), |
| 972 |
onClick: () => { |
| 973 |
if (show_flags && '' === show_labels) { |
| 974 |
createWarningNotice((0,external_this_wp_i18n_.__)('Flags cannot be hidden if labels are not displayed.', 'polylang')); |
| 975 |
return; |
| 976 |
} |
| 977 |
setAttributes({ |
| 978 |
show_flags: !show_flags |
| 979 |
}); |
| 980 |
} |
| 981 |
}), 'select' !== layout && /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(external_this_wp_components_.ToolbarDropdownMenu, { |
| 982 |
icon: /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)("span", { |
| 983 |
className: "dashicons dashicons-editor-textcolor" |
| 984 |
}), |
| 985 |
label: (0,external_this_wp_i18n_.__)('Labels', 'polylang'), |
| 986 |
controls: toolbarLabelControls |
| 987 |
})] |
| 988 |
}) |
| 989 |
})] |
| 990 |
}); |
| 991 |
}; |
| 992 |
;// ./js/src/blocks/language-switcher/edit.js |
| 993 |
/** |
| 994 |
* Edit callback for language switcher block. |
| 995 |
*/ |
| 996 |
|
| 997 |
/** |
| 998 |
* WordPress dependencies |
| 999 |
*/ |
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
/** |
| 1004 |
* Internal dependencies |
| 1005 |
*/ |
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
/** |
| 1012 |
* Edit callback for language switcher block. |
| 1013 |
* |
| 1014 |
* @param {Object} props Block properties. |
| 1015 |
* @param {Object} props.attributes Block attributes. |
| 1016 |
* @param {Function} props.setAttributes Function to set block attributes. |
| 1017 |
* @return {ReactElement} The block content and controls. |
| 1018 |
*/ |
| 1019 |
|
| 1020 |
const Edit = ({ |
| 1021 |
attributes, |
| 1022 |
setAttributes |
| 1023 |
}) => { |
| 1024 |
const languages = useLanguagesList(); |
| 1025 |
return /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsxs)("div", { |
| 1026 |
...(0,external_this_wp_blockEditor_.useBlockProps)(), |
| 1027 |
children: [/*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(SwitcherControls, { |
| 1028 |
attributes: attributes, |
| 1029 |
setAttributes: setAttributes |
| 1030 |
}), /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(external_this_wp_components_.Disabled, { |
| 1031 |
children: /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(LanguagesContext.Provider, { |
| 1032 |
value: { |
| 1033 |
languages |
| 1034 |
}, |
| 1035 |
children: /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(RenderedSwitcher, { |
| 1036 |
attributes: attributes |
| 1037 |
}) |
| 1038 |
}) |
| 1039 |
})] |
| 1040 |
}); |
| 1041 |
}; |
| 1042 |
;// ./src/modules/Blocks/Language_Switcher/Standard/block.json |
| 1043 |
const block_namespaceObject = /*#__PURE__*/JSON.parse('{"UU":"polylang/language-switcher"}'); |
| 1044 |
;// ./js/src/blocks/language-switcher/index.js |
| 1045 |
/** |
| 1046 |
* Register language switcher block. |
| 1047 |
*/ |
| 1048 |
|
| 1049 |
/** |
| 1050 |
* WordPress dependencies |
| 1051 |
*/ |
| 1052 |
|
| 1053 |
|
| 1054 |
/** |
| 1055 |
* Internal dependencies |
| 1056 |
*/ |
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
(0,external_this_wp_blocks_.registerBlockType)(block_namespaceObject.UU, { |
| 1062 |
icon: icons_translation, |
| 1063 |
edit: Edit, |
| 1064 |
deprecated: deprecated |
| 1065 |
}); |
| 1066 |
// EXTERNAL MODULE: external {"this":["wp","hooks"]} |
| 1067 |
var external_this_wp_hooks_ = __webpack_require__(873); |
| 1068 |
;// ./js/src/blocks/navigation-language-switcher/deprecated.js |
| 1069 |
/** |
| 1070 |
* Deprecated navigation language switcher block. |
| 1071 |
*/ |
| 1072 |
|
| 1073 |
const deprecated_V2Attributes = { |
| 1074 |
layout: 'horizontal', |
| 1075 |
show_labels: 'names', |
| 1076 |
show_flags: false, |
| 1077 |
force_home: false, |
| 1078 |
hide_current: false, |
| 1079 |
hide_if_no_translation: false, |
| 1080 |
flag_aspect_ratio: '3:2', |
| 1081 |
flag_border_radius: 0, |
| 1082 |
flag_width: '18px', |
| 1083 |
flag_label_spacing: '0.3em', |
| 1084 |
className: '' |
| 1085 |
}; |
| 1086 |
const deprecated_v1 = { |
| 1087 |
attributes: { |
| 1088 |
dropdown: { |
| 1089 |
type: 'boolean', |
| 1090 |
default: false |
| 1091 |
}, |
| 1092 |
show_names: { |
| 1093 |
type: 'boolean', |
| 1094 |
default: true |
| 1095 |
}, |
| 1096 |
show_flags: { |
| 1097 |
type: 'boolean', |
| 1098 |
default: false |
| 1099 |
}, |
| 1100 |
force_home: { |
| 1101 |
type: 'boolean', |
| 1102 |
default: false |
| 1103 |
}, |
| 1104 |
hide_current: { |
| 1105 |
type: 'boolean', |
| 1106 |
default: false |
| 1107 |
}, |
| 1108 |
hide_if_no_translation: { |
| 1109 |
type: 'boolean', |
| 1110 |
default: false |
| 1111 |
}, |
| 1112 |
className: { |
| 1113 |
type: 'string', |
| 1114 |
default: '' |
| 1115 |
} |
| 1116 |
}, |
| 1117 |
isEligible: attributes => 'dropdown' in attributes || 'show_names' in attributes, |
| 1118 |
migrate(attributes) { |
| 1119 |
const { |
| 1120 |
dropdown, |
| 1121 |
show_names, |
| 1122 |
show_flags, |
| 1123 |
force_home, |
| 1124 |
hide_current, |
| 1125 |
hide_if_no_translation, |
| 1126 |
className |
| 1127 |
} = attributes; |
| 1128 |
return { |
| 1129 |
...deprecated_V2Attributes, |
| 1130 |
layout: dropdown ? 'dropdown' : 'horizontal', |
| 1131 |
show_labels: show_names ? 'names' : '', |
| 1132 |
show_flags: show_names ? show_flags : true, |
| 1133 |
force_home, |
| 1134 |
hide_current, |
| 1135 |
hide_if_no_translation, |
| 1136 |
className: className || '' |
| 1137 |
}; |
| 1138 |
} |
| 1139 |
}; |
| 1140 |
/* harmony default export */ const navigation_language_switcher_deprecated = ([deprecated_v1]); |
| 1141 |
// EXTERNAL MODULE: external {"this":["wp","editor"]} |
| 1142 |
var external_this_wp_editor_ = __webpack_require__(2); |
| 1143 |
;// ./node_modules/@wpsyntex/polylang-react-library/build/hooks/use-current-language.js |
| 1144 |
/** |
| 1145 |
* WordPress dependencies |
| 1146 |
*/ |
| 1147 |
|
| 1148 |
// This package is not found in `@wordpress/scripts` like others (peer dependency). |
| 1149 |
// eslint-disable-next-line import/no-unresolved |
| 1150 |
|
| 1151 |
|
| 1152 |
/** |
| 1153 |
* Custom hook to get the current language from the editor. |
| 1154 |
* |
| 1155 |
* @param {Array} languages The languages list. |
| 1156 |
* @return {Object|null} The current language, `null` if not found. |
| 1157 |
*/ |
| 1158 |
const useCurrentLanguage = languages => { |
| 1159 |
const currentPost = (0,external_this_wp_data_.useSelect)(select => select(external_this_wp_editor_.store).getCurrentPost()); |
| 1160 |
if (!languages || !currentPost) { |
| 1161 |
return null; |
| 1162 |
} |
| 1163 |
const currentLanguageSlug = currentPost.lang ?? pllEditorCurrentLanguageSlug; // eslint-disable-line no-undef |
| 1164 |
|
| 1165 |
const currentLanguage = languages.find(language => { |
| 1166 |
return language.slug === currentLanguageSlug; |
| 1167 |
}); |
| 1168 |
return currentLanguage ? currentLanguage : null; |
| 1169 |
}; |
| 1170 |
;// ./js/src/blocks/navigation-language-switcher/rendered-switcher.js |
| 1171 |
/** |
| 1172 |
* WordPress dependencies |
| 1173 |
*/ |
| 1174 |
|
| 1175 |
|
| 1176 |
/** |
| 1177 |
* External dependencies |
| 1178 |
*/ |
| 1179 |
|
| 1180 |
|
| 1181 |
/** |
| 1182 |
* Internal dependencies |
| 1183 |
*/ |
| 1184 |
|
| 1185 |
|
| 1186 |
|
| 1187 |
|
| 1188 |
/** |
| 1189 |
* Rendered switcher component. |
| 1190 |
* |
| 1191 |
* @param {Object} props The component props. |
| 1192 |
* @param {Object} props.attributes The block attributes. |
| 1193 |
* @param {Object} props.context The block context. |
| 1194 |
* @return {ReactElement} The rendered switcher. |
| 1195 |
*/ |
| 1196 |
|
| 1197 |
const rendered_switcher_RenderedSwitcher = ({ |
| 1198 |
attributes, |
| 1199 |
context |
| 1200 |
}) => { |
| 1201 |
const { |
| 1202 |
layout, |
| 1203 |
show_labels, |
| 1204 |
show_flags, |
| 1205 |
flag_border_radius, |
| 1206 |
flag_width, |
| 1207 |
flag_label_spacing |
| 1208 |
} = attributes; |
| 1209 |
const { |
| 1210 |
showSubmenuIcon, |
| 1211 |
openSubmenusOnClick |
| 1212 |
} = context; |
| 1213 |
const { |
| 1214 |
languages |
| 1215 |
} = (0,external_this_wp_element_.useContext)(LanguagesContext); |
| 1216 |
const currentLanguage = useCurrentLanguage(languages); |
| 1217 |
const isDropdown = layout === 'dropdown'; |
| 1218 |
const languagesToRender = useCuratedLanguages(languages, currentLanguage, isDropdown); |
| 1219 |
const labelSpacing = getLabelSpacing(show_labels, flag_label_spacing); |
| 1220 |
const withSubmenuIcon = isDropdown && (showSubmenuIcon || openSubmenusOnClick); |
| 1221 |
const linkProps = { |
| 1222 |
showLabels: show_labels, |
| 1223 |
showFlags: show_flags, |
| 1224 |
flagBorderRadius: flag_border_radius, |
| 1225 |
flagWidth: flag_width, |
| 1226 |
labelSpacing |
| 1227 |
}; |
| 1228 |
return /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)((react_jsx_runtime_production_min_namespaceFn().Fragment), { |
| 1229 |
children: languagesToRender.map(language => { |
| 1230 |
return /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsxs)(external_this_wp_element_.Fragment, { |
| 1231 |
children: [/*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(SwitcherLanguageLink, { |
| 1232 |
language: language, |
| 1233 |
...linkProps |
| 1234 |
}), withSubmenuIcon && /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)("span", { |
| 1235 |
className: "wp-block-navigation__submenu-icon", |
| 1236 |
children: /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(submenu, {}) |
| 1237 |
})] |
| 1238 |
}, language.slug); |
| 1239 |
}) |
| 1240 |
}); |
| 1241 |
}; |
| 1242 |
;// ./js/src/blocks/navigation-language-switcher/edit.js |
| 1243 |
/** |
| 1244 |
* Edit callback for navigation language switcher block. |
| 1245 |
*/ |
| 1246 |
|
| 1247 |
/** |
| 1248 |
* WordPress dependencies |
| 1249 |
*/ |
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
/** |
| 1254 |
* Internal dependencies |
| 1255 |
*/ |
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
/** |
| 1262 |
* Edit callback for navigation language switcher block. |
| 1263 |
* |
| 1264 |
* @param {Object} props Block properties. |
| 1265 |
* @param {Object} props.attributes Block attributes. |
| 1266 |
* @param {Object} props.context Block context. |
| 1267 |
* @param {Function} props.setAttributes Function to set block attributes. |
| 1268 |
* @return {ReactElement} The block content and controls. |
| 1269 |
*/ |
| 1270 |
|
| 1271 |
const edit_Edit = ({ |
| 1272 |
attributes, |
| 1273 |
context, |
| 1274 |
setAttributes |
| 1275 |
}) => { |
| 1276 |
const languages = useLanguagesList(); |
| 1277 |
const { |
| 1278 |
show_flags, |
| 1279 |
flag_aspect_ratio |
| 1280 |
} = attributes; |
| 1281 |
const aspectRatioClass = show_flags && flag_aspect_ratio ? `pll-aspect-ratio-${flag_aspect_ratio.replace(':', '')}` : ''; |
| 1282 |
return /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsxs)("div", { |
| 1283 |
...(0,external_this_wp_blockEditor_.useBlockProps)({ |
| 1284 |
className: aspectRatioClass || undefined |
| 1285 |
}), |
| 1286 |
children: [/*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(SwitcherControls, { |
| 1287 |
attributes: attributes, |
| 1288 |
setAttributes: setAttributes, |
| 1289 |
layoutOptions: ['horizontal', 'dropdown'] |
| 1290 |
}), /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(external_this_wp_components_.Disabled, { |
| 1291 |
children: /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(LanguagesContext.Provider, { |
| 1292 |
value: { |
| 1293 |
languages |
| 1294 |
}, |
| 1295 |
children: /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(rendered_switcher_RenderedSwitcher, { |
| 1296 |
attributes: attributes, |
| 1297 |
context: context |
| 1298 |
}) |
| 1299 |
}) |
| 1300 |
})] |
| 1301 |
}); |
| 1302 |
}; |
| 1303 |
;// ./src/modules/Blocks/Language_Switcher/Navigation/block.json |
| 1304 |
const Navigation_block_namespaceObject = /*#__PURE__*/JSON.parse('{"UU":"polylang/navigation-language-switcher"}'); |
| 1305 |
;// ./js/src/blocks/navigation-language-switcher/menu-items-converter.js |
| 1306 |
/** |
| 1307 |
* Menu items converter |
| 1308 |
*/ |
| 1309 |
|
| 1310 |
/** |
| 1311 |
* WordPress dependencies |
| 1312 |
*/ |
| 1313 |
|
| 1314 |
|
| 1315 |
/** |
| 1316 |
* Internal dependencies |
| 1317 |
*/ |
| 1318 |
|
| 1319 |
|
| 1320 |
/** |
| 1321 |
* Apply a callback function on each block of the blocks list. |
| 1322 |
* |
| 1323 |
* @param {Array} blocks The list of blocks to process. |
| 1324 |
* @param {Array} menuItems The initial menu items from where the blocks are converted to. |
| 1325 |
* @param {Object} blocksMapping The mapping between the menu items and their corresponding blocks. |
| 1326 |
* @param {mapper} mapper A callback to change the converted block by another one if necessary |
| 1327 |
* @return {Array} Array of blocks updated. |
| 1328 |
*/ |
| 1329 |
function mapBlockTree(blocks, menuItems, blocksMapping, mapper) { |
| 1330 |
/** |
| 1331 |
* A function to apply to each block to convert it if necessary by applying the `mapper` filter. |
| 1332 |
* |
| 1333 |
* @param {Object} block The block to replace or not. |
| 1334 |
* @return {Object} The new block potentially replaced by the `mapper`. |
| 1335 |
*/ |
| 1336 |
const convertBlock = block => ({ |
| 1337 |
...mapper(block, menuItems, blocksMapping), |
| 1338 |
innerBlocks: mapBlockTree(block.innerBlocks, menuItems, blocksMapping, mapper) |
| 1339 |
}); |
| 1340 |
return blocks.map(convertBlock); |
| 1341 |
} |
| 1342 |
|
| 1343 |
/** |
| 1344 |
* A filter to detect the `core/navigation-link` block not correctly converted from the language switcher menu item |
| 1345 |
* and convert it to its corresponding `polylang/navigation-language-switcher` block. |
| 1346 |
* |
| 1347 |
* @callback mapper |
| 1348 |
* @param {Object} block The block converted from the menu item. |
| 1349 |
* @param {Array} menuItems The initial menu items from where the blocks are converted to. |
| 1350 |
* @param {Object} blocksMapping The mapping between the menu items and their corresponding blocks. |
| 1351 |
* @return {Object} The block correctly converted. |
| 1352 |
*/ |
| 1353 |
const blocksFilter = (block, menuItems, blocksMapping) => { |
| 1354 |
if (block.name === 'core/navigation-link' && block.attributes?.url === '#pll_switcher') { |
| 1355 |
const menuItem = menuItems.find(item => item.url === '#pll_switcher'); // Get the corresponding menu item. |
| 1356 |
const attributes = menuItem.meta._pll_menu_item; // Get its options. |
| 1357 |
const newBlock = (0,external_this_wp_blocks_.createBlock)(Navigation_block_namespaceObject.UU, attributes); |
| 1358 |
blocksMapping[menuItem.id] = newBlock.clientId; // Update the blocks mapping. |
| 1359 |
return newBlock; |
| 1360 |
} |
| 1361 |
return block; |
| 1362 |
}; |
| 1363 |
|
| 1364 |
/** |
| 1365 |
* A filter callback hooked to `blocks.navigation.__unstableMenuItemsToBlocks`. |
| 1366 |
* |
| 1367 |
* @param {Array} blocks The list of blocks to process. |
| 1368 |
* @param {Array} menuItems The initial menu items from where the blocks are converted to. |
| 1369 |
* @return {Array} Array of blocks updated. |
| 1370 |
*/ |
| 1371 |
const menuItemsToBlocksFilter = (blocks, menuItems) => ({ |
| 1372 |
...blocks, |
| 1373 |
innerBlocks: mapBlockTree(blocks.innerBlocks, menuItems, blocks.mapping, blocksFilter) |
| 1374 |
}); |
| 1375 |
;// ./js/src/blocks/navigation-language-switcher/index.js |
| 1376 |
/** |
| 1377 |
* Register navigation language switcher block. |
| 1378 |
*/ |
| 1379 |
|
| 1380 |
/** |
| 1381 |
* WordPress Dependencies |
| 1382 |
*/ |
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
/** |
| 1387 |
* Internal dependencies |
| 1388 |
*/ |
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
(0,external_this_wp_blocks_.registerBlockType)(Navigation_block_namespaceObject.UU, { |
| 1395 |
icon: icons_translation, |
| 1396 |
transforms: { |
| 1397 |
from: [{ |
| 1398 |
type: 'block', |
| 1399 |
blocks: ['core/navigation-link'], |
| 1400 |
transform: () => (0,external_this_wp_blocks_.createBlock)(Navigation_block_namespaceObject.UU) |
| 1401 |
}] |
| 1402 |
}, |
| 1403 |
edit: edit_Edit, |
| 1404 |
deprecated: navigation_language_switcher_deprecated |
| 1405 |
}); |
| 1406 |
|
| 1407 |
/** |
| 1408 |
* Hooks to the classic menu conversion to core/navigation block to be able to convert |
| 1409 |
* the language switcher menu item to its corresponding block. |
| 1410 |
*/ |
| 1411 |
(0,external_this_wp_hooks_.addFilter)('blocks.navigation.__unstableMenuItemsToBlocks', 'polylang/include-language-switcher', menuItemsToBlocksFilter); |
| 1412 |
;// ./js/src/blocks/index.js |
| 1413 |
/** |
| 1414 |
* Registers Polylang blocks in the editors and enables attributes controls. |
| 1415 |
*/ |
| 1416 |
|
| 1417 |
|
| 1418 |
})(); |
| 1419 |
|
| 1420 |
this.polylang = __webpack_exports__; |
| 1421 |
/******/ })() |
| 1422 |
; |