PluginProbe
Polylang / trunk
Polylang vtrunk
3.8.10 3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 All 234 releases
← All changes | js/build/blocks.js +865 -521 3.8.7 → trunk View file →
@@ -1,40 +1,7 @@
1 1 /******/ (() => { // webpackBootstrap
2 2 /******/ var __webpack_modules__ = ({
3 3
4 -/***/ 20
5 -(__unused_webpack_module, exports, __webpack_require__) {
6 -
7 -"use strict";
8 -/**
9 - * @license React
10 - * react-jsx-runtime.production.min.js
11 - *
12 - * Copyright (c) Facebook, Inc. and its affiliates.
13 - *
14 - * This source code is licensed under the MIT license found in the
15 - * LICENSE file in the root directory of this source tree.
16 - */
17 -var f=__webpack_require__(677),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};
18 -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;
19 -
20 -
21 -/***/ },
22 -
23 -/***/ 848
24 -(module, __unused_webpack_exports, __webpack_require__) {
25 -
26 -"use strict";
27 -
28 -
29 -if (true) {
30 - module.exports = __webpack_require__(20);
31 -} else // removed by dead control flow
32 -{}
33 -
34 -
35 -/***/ },
36 -
37 4 /***/ 677
38 5 (module) {
39 6
40 7 module.exports = (function() { return this["React"]; }());
@@ -40,15 +7,8 @@
40 7 module.exports = (function() { return this["React"]; }());
41 8
42 9 /***/ },
43 10
44 -/***/ 419
45 -(module) {
46 -
47 -module.exports = (function() { return this["lodash"]; }());
48 -
49 -/***/ },
50 -
51 11 /***/ 631
52 12 (module) {
53 13
54 14 module.exports = (function() { return this["wp"]["apiFetch"]; }());
@@ -110,8 +70,15 @@
110 70 module.exports = (function() { return this["wp"]["i18n"]; }());
111 71
112 72 /***/ },
113 73
74 +/***/ 672
75 +(module) {
76 +
77 +module.exports = (function() { return this["wp"]["notices"]; }());
78 +
79 +/***/ },
80 +
114 81 /***/ 933
115 82 (module) {
116 83
117 84 module.exports = (function() { return this["wp"]["primitives"]; }());
@@ -145,50 +112,46 @@
145 112 /******/ }
146 113 /******/
147 114 /************************************************************************/
148 115 /******/ /* webpack/runtime/compat get default export */
149 -/******/ (() => {
150 -/******/ // getDefaultExport function for compatibility with non-harmony modules
151 -/******/ __webpack_require__.n = (module) => {
152 -/******/ const getter = module && module.__esModule ?
153 -/******/ () => (module['default']) :
154 -/******/ () => (module);
155 -/******/ __webpack_require__.d(getter, { a: getter });
156 -/******/ return getter;
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;
157 139 /******/ };
158 -/******/ })();
140 +/******/ };
159 141 /******/
160 142 /******/ /* webpack/runtime/define property getters */
161 -/******/ (() => {
162 -/******/ // define getter/value functions for harmony exports
163 -/******/ __webpack_require__.d = (exports, definition) => {
164 -/******/ if(Array.isArray(definition)) {
165 -/******/ var i = 0;
166 -/******/ while(i < definition.length) {
167 -/******/ var key = definition[i++];
168 -/******/ var binding = definition[i++];
169 -/******/ if(!__webpack_require__.o(exports, key)) {
170 -/******/ if(binding === 0) {
171 -/******/ Object.defineProperty(exports, key, { enumerable: true, value: definition[i++] });
172 -/******/ } else {
173 -/******/ Object.defineProperty(exports, key, { enumerable: true, get: binding });
174 -/******/ }
175 -/******/ } else if(binding === 0) { i++; }
176 -/******/ }
177 -/******/ } else {
178 -/******/ for(var key in definition) {
179 -/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
180 -/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
181 -/******/ }
182 -/******/ }
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] });
183 148 /******/ }
184 -/******/ };
185 -/******/ })();
149 +/******/ }
150 +/******/ };
186 151 /******/
187 152 /******/ /* webpack/runtime/hasOwnProperty shorthand */
188 -/******/ (() => {
189 -/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
190 -/******/ })();
153 +/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop));
191 154 /******/
192 155 /************************************************************************/
193 156 let __webpack_exports__ = {};
194 157 // This entry needs to be wrapped in an IIFE because it needs to be in strict mode.
@@ -194,14 +157,47 @@
194 157 // This entry needs to be wrapped in an IIFE because it needs to be in strict mode.
195 158 (() => {
196 159 "use strict";
197 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 +
198 193 // EXTERNAL MODULE: external {"this":["wp","blocks"]}
199 194 var external_this_wp_blocks_ = __webpack_require__(545);
200 195 // EXTERNAL MODULE: external {"this":["wp","primitives"]}
201 196 var external_this_wp_primitives_ = __webpack_require__(933);
202 -// EXTERNAL MODULE: ./node_modules/react/jsx-runtime.js
203 -var jsx_runtime = __webpack_require__(848);
197 +;// ./node_modules/react/jsx-runtime.js
198 +jsx_runtime_namespaceFn();
199 +
204 200 ;// ./node_modules/@wpsyntex/polylang-react-library/build/icons/translation.js
205 201 /**
206 202 * Translation icon - translation Dashicon.
207 203 */
@@ -211,148 +207,337 @@
211 207 */
212 208
213 209
214 210 const isPrimitivesComponents = 'undefined' !== typeof wp.primitives;
215 -const translation = isPrimitivesComponents ? /*#__PURE__*/(0,jsx_runtime.jsx)(external_this_wp_primitives_.SVG, {
211 +const translation = isPrimitivesComponents ? /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(external_this_wp_primitives_.SVG, {
216 212 width: "20",
217 213 height: "20",
218 214 xmlns: "http://www.w3.org/2000/svg",
219 215 viewBox: "0 0 20 20",
220 - children: /*#__PURE__*/(0,jsx_runtime.jsx)(external_this_wp_primitives_.Path, {
216 + children: /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(external_this_wp_primitives_.Path, {
221 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"
222 218 })
223 219 }) : 'translation';
224 220 /* harmony default export */ const icons_translation = (translation);
225 -// EXTERNAL MODULE: external {"this":["wp","i18n"]}
226 -var external_this_wp_i18n_ = __webpack_require__(75);
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]);
227 294 // EXTERNAL MODULE: external {"this":["wp","blockEditor"]}
228 295 var external_this_wp_blockEditor_ = __webpack_require__(89);
229 296 // EXTERNAL MODULE: external {"this":["wp","components"]}
230 297 var external_this_wp_components_ = __webpack_require__(959);
231 -// EXTERNAL MODULE: external "lodash"
232 -var external_lodash_ = __webpack_require__(419);
233 -;// ./js/src/blocks/language-switcher-edit.js
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
234 304 /**
235 - * Language switcher block edit.
305 + * WordPress dependencies
236 306 */
237 307
308 +
309 +
238 310 /**
239 - * External dependencies
311 + * Custom hook to get the languages list.
312 + *
313 + * @return {Array|null} The languages list, `null` if not loaded yet.
240 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 + */
241 329
242 330
243 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 +/**
244 360 * WordPress dependencies
245 361 */
246 362
247 363
248 -const i18nAttributeStrings = pll_block_editor_blocks_settings;
249 -function createLanguageSwitcherEdit(props) {
250 - const createToggleAttribute = function (propName) {
251 - return () => {
252 - const value = props.attributes[propName];
253 - const {
254 - setAttributes
255 - } = props;
256 - let updatedAttributes = {
257 - [propName]: !value
258 - };
259 - let forcedAttributeName;
260 - let forcedAttributeUnchecked;
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
261 378
262 - // Both show_names and show_flags attributes can't be unchecked together.
263 - switch (propName) {
264 - case 'show_names':
265 - forcedAttributeName = 'show_flags';
266 - forcedAttributeUnchecked = !props.attributes[forcedAttributeName];
267 - break;
268 - case 'show_flags':
269 - forcedAttributeName = 'show_names';
270 - forcedAttributeUnchecked = !props.attributes[forcedAttributeName];
271 - break;
272 - }
273 - if ('show_names' === propName || 'show_flags' === propName) {
274 - if (value && forcedAttributeUnchecked) {
275 - updatedAttributes = (0,external_lodash_.assign)(updatedAttributes, {
276 - [forcedAttributeName]: forcedAttributeUnchecked
277 - });
278 - }
279 - }
280 - setAttributes(updatedAttributes);
281 - };
282 - };
283 - const toggleDropdown = createToggleAttribute('dropdown');
284 - const toggleShowNames = createToggleAttribute('show_names');
285 - const toggleShowFlags = createToggleAttribute('show_flags');
286 - const toggleForceHome = createToggleAttribute('force_home');
287 - const toggleHideCurrent = createToggleAttribute('hide_current');
288 - const toggleHideIfNoTranslation = createToggleAttribute('hide_if_no_translation');
289 - const {
290 - dropdown,
291 - show_names,
292 - show_flags,
293 - force_home,
294 - hide_current,
295 - hide_if_no_translation
296 - } = props.attributes;
297 - function ToggleControlDropdown() {
298 - return /*#__PURE__*/(0,jsx_runtime.jsx)(external_this_wp_components_.ToggleControl, {
299 - label: i18nAttributeStrings.dropdown,
300 - checked: dropdown,
301 - onChange: toggleDropdown
302 - });
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}`);
303 424 }
304 - function ToggleControlShowNames() {
305 - return /*#__PURE__*/(0,jsx_runtime.jsx)(external_this_wp_components_.ToggleControl, {
306 - label: i18nAttributeStrings.show_names,
307 - checked: show_names // eslint-disable-line camelcase
308 - ,
309 - onChange: toggleShowNames
310 - });
425 + if (showFlags) {
426 + classes.push(`pll-aspect-ratio-${flagAspectRatio.replace(':', '')}`);
311 427 }
312 - function ToggleControlShowFlags() {
313 - return /*#__PURE__*/(0,jsx_runtime.jsx)(external_this_wp_components_.ToggleControl, {
314 - label: i18nAttributeStrings.show_flags,
315 - checked: show_flags // eslint-disable-line camelcase
316 - ,
317 - onChange: toggleShowFlags
318 - });
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();
319 444 }
320 - function ToggleControlForceHome() {
321 - return /*#__PURE__*/(0,jsx_runtime.jsx)(external_this_wp_components_.ToggleControl, {
322 - label: i18nAttributeStrings.force_home,
323 - checked: force_home // eslint-disable-line camelcase
324 - ,
325 - onChange: toggleForceHome
326 - });
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;
327 458 }
328 - function ToggleControlHideCurrent() {
329 - return /*#__PURE__*/(0,jsx_runtime.jsx)(external_this_wp_components_.ToggleControl, {
330 - label: i18nAttributeStrings.hide_current,
331 - checked: hide_current // eslint-disable-line camelcase
332 - ,
333 - onChange: toggleHideCurrent
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 + }
334 501 });
335 - }
336 - function ToggleControlHideIfNoTranslations() {
337 - return /*#__PURE__*/(0,jsx_runtime.jsx)(external_this_wp_components_.ToggleControl, {
338 - label: i18nAttributeStrings.hide_if_no_translation,
339 - checked: hide_if_no_translation // eslint-disable-line camelcase
340 - ,
341 - onChange: toggleHideIfNoTranslation
342 - });
343 - }
344 - return {
345 - ToggleControlDropdown,
346 - ToggleControlShowNames,
347 - ToggleControlShowFlags,
348 - ToggleControlForceHome,
349 - ToggleControlHideCurrent,
350 - ToggleControlHideIfNoTranslations
351 - };
352 -}
353 -// EXTERNAL MODULE: external {"this":["wp","element"]}
354 -var external_this_wp_element_ = __webpack_require__(601);
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 +};
355 540 // EXTERNAL MODULE: external {"this":["wp","data"]}
356 541 var external_this_wp_data_ = __webpack_require__(987);
357 542 ;// ./js/src/blocks/hooks/use-current-language-with-editor-context.js
358 543 /**
@@ -417,220 +602,394 @@
417 602 *
418 603 * @type {React.Context<null>}
419 604 */
420 605 const LanguagesContext = (0,external_this_wp_element_.createContext)(null);
421 -;// ./js/src/blocks/hooks/use-memoized-switcher-label.js
606 +;// ./js/src/blocks/language-switcher/rendered-switcher.js
422 607 /**
423 608 * WordPress dependencies
424 609 */
425 -// '@wordpress/element' is provided by WordPress core.
426 -// eslint-disable-next-line import/no-extraneous-dependencies
427 610
428 611
429 612 /**
430 - * Hook to memoize the switcher label.
431 - *
432 - * @param {Object} language The language object.
433 - * @param {boolean} showFlags Whether to show the flags.
434 - * @param {boolean} showNames Whether to show the names.
435 - * @return {Object} The memoized switcher label containing the text and the flag.
613 + * External dependencies
436 614 */
437 -const useMemoizedSwitcherLabel = (language, showFlags, showNames) => {
438 - const {
439 - text,
440 - flag
441 - } = (0,external_this_wp_element_.useMemo)(() => {
442 - let memoizedText = '';
443 - if (showNames) {
444 - if (showFlags) {
445 - memoizedText = ` ${language.name}`;
446 - } else {
447 - memoizedText = language.name;
448 - }
449 - }
450 - const memoizedFlag = showFlags ? language.flag : '';
451 - return {
452 - text: memoizedText,
453 - flag: memoizedFlag
454 - };
455 - }, [language, showFlags, showNames]);
456 - return {
457 - text,
458 - flag
459 - };
460 -};
461 -;// ./js/src/blocks/language-switcher/components/switcher-list-element.js
615 +
616 +
462 617 /**
463 618 * Internal dependencies
464 619 */
465 620
466 621
467 -/**
468 - * Switcher list element component.
469 - *
470 - * @param {Object} props Component props.
471 - * @param {Object} props.language Language object.
472 - * @param {boolean} props.showFlags Whether to show the flags.
473 - * @param {boolean} props.showNames Whether to show the names.
474 - * @return {ReactElement} The Switcher element component.
475 - */
476 622
477 -const SwitcherListElement = ({
478 - language,
479 - showFlags,
480 - showNames
481 -}) => {
482 - const {
483 - text,
484 - flag
485 - } = useMemoizedSwitcherLabel(language, showFlags, showNames);
486 - return /*#__PURE__*/(0,jsx_runtime.jsxs)("li", {
487 - children: [/*#__PURE__*/(0,jsx_runtime.jsx)("span", {
488 - dangerouslySetInnerHTML: {
489 - __html: flag
490 - }
491 - }), " ", text, " "]
492 - });
493 -};
494 -;// ./js/src/blocks/language-switcher/components/switcher-ui.js
495 -/**
496 - * Internal dependencies
497 - */
498 623
499 624
500 625 /**
501 - * Switcher UI component.
626 + * Rendered switcher component.
502 627 *
503 - * @param {Object} props The component props.
504 - * @param {Array} props.languages The languages to display.
505 - * @param {boolean} props.showFlags Whether to show the flags.
506 - * @param {boolean} props.showNames Whether to show the names.
507 - * @param {boolean} props.isDropdown Whether to show the dropdown.
508 - * @return {ReactElement} The Switcher UI component.
628 + * @param {Object} props The component props.
629 + * @param {Object} props.attributes The block attributes.
630 + * @return {ReactElement} The rendered switcher.
509 631 */
510 632
511 -const SwitcherUI = ({
512 - languages,
513 - showFlags,
514 - showNames,
515 - isDropdown
633 +const RenderedSwitcher = ({
634 + attributes
516 635 }) => {
517 - if (isDropdown) {
518 - return /*#__PURE__*/(0,jsx_runtime.jsx)("select", {
519 - children: languages.map(language => {
520 - return /*#__PURE__*/(0,jsx_runtime.jsx)("option", {
521 - value: language.slug,
522 - children: language.name
523 - }, language.slug);
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 + })]
524 674 })
525 675 });
526 676 }
527 - return /*#__PURE__*/(0,jsx_runtime.jsx)("ul", {
528 - children: languages.map(language => {
529 - return /*#__PURE__*/(0,jsx_runtime.jsx)(SwitcherListElement, {
530 - language: language,
531 - showFlags: showFlags,
532 - showNames: showNames
533 - }, language.slug);
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 + })
534 702 })
535 703 });
536 704 };
537 -;// ./node_modules/@wpsyntex/polylang-react-library/build/hooks/use-curated-languages.js
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
538 710 /**
539 711 * WordPress dependencies
540 712 */
541 713
542 714
543 -/**
544 - * Hook to curate the languages.
545 - * Returns an array of languages ensuring that the current language is always the first one.
546 - *
547 - * @param {Object[]} languages The languages.
548 - * @param {Object} currentLanguage The current language.
549 - * @param {boolean} reduceToOneItem Whether to reduce the languages to one item.
550 - * @return {Object[]} The curated languages.
551 - */
552 -const useCuratedLanguages = (languages, currentLanguage, reduceToOneItem) => {
553 - const curatedLanguages = (0,external_this_wp_element_.useMemo)(() => {
554 - if (!currentLanguage) {
555 - return [];
556 - }
557 - if (reduceToOneItem) {
558 - return [currentLanguage];
559 - }
560 - return [currentLanguage, ...languages.filter(language => {
561 - return language.slug !== currentLanguage.slug;
562 - })];
563 - }, [languages, currentLanguage, reduceToOneItem]);
564 - return curatedLanguages;
565 -};
566 -;// ./js/src/blocks/language-switcher/components/switcher-container.js
567 -/**
568 - * WordPress dependencies
569 - */
570 715
571 716
572 -/**
573 - * Internal dependencies
574 - */
575 717
576 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 +}];
577 759
578 -
579 -
580 760 /**
581 - * Switcher container component.
761 + * Switcher controls component for toolbar and inspector controls.
582 762 *
583 - * @param {Object} props The component props.
584 - * @param {Object} props.attributes The block attributes.
585 - * @return {ReactElement} The Switcher component.
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.
586 768 */
587 -
588 -const SwitcherContainer = ({
589 - attributes
769 +const SwitcherControls = ({
770 + attributes,
771 + setAttributes,
772 + layoutOptions = ['horizontal', 'vertical', 'dropdown', 'select']
590 773 }) => {
591 774 const {
592 - dropdown,
775 + layout,
776 + show_labels,
593 777 show_flags,
594 - show_names
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
595 785 } = attributes;
596 786 const {
597 - languages
598 - } = (0,external_this_wp_element_.useContext)(LanguagesContext);
599 - const currentLanguage = useCurrentLanguageWithEditorContext(languages);
600 - const curatedLanguages = useCuratedLanguages(languages, currentLanguage, dropdown);
601 - return /*#__PURE__*/(0,jsx_runtime.jsx)(SwitcherUI, {
602 - languages: curatedLanguages,
603 - showFlags: show_flags,
604 - showNames: show_names,
605 - isDropdown: dropdown
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 + })]
606 990 });
607 991 };
608 -// EXTERNAL MODULE: external {"this":["wp","apiFetch"]}
609 -var external_this_wp_apiFetch_ = __webpack_require__(631);
610 -var external_this_wp_apiFetch_default = /*#__PURE__*/__webpack_require__.n(external_this_wp_apiFetch_);
611 -;// ./node_modules/@wpsyntex/polylang-react-library/build/hooks/use-languages-list.js
612 -/**
613 - * WordPress dependencies
614 - */
615 -
616 -
617 -
618 -/**
619 - * Custom hook to get the languages list.
620 - *
621 - * @return {Array|null} The languages list, `null` if not loaded yet.
622 - */
623 -const useLanguagesList = () => {
624 - const [languages, setLanguages] = (0,external_this_wp_element_.useState)(null);
625 - (0,external_this_wp_element_.useEffect)(() => {
626 - external_this_wp_apiFetch_default()({
627 - path: '/pll/v1/languages',
628 - method: 'GET'
629 - }).then(response => setLanguages(response));
630 - }, []);
631 - return languages;
632 -};
633 992 ;// ./js/src/blocks/language-switcher/edit.js
634 993 /**
635 994 * Edit callback for language switcher block.
636 995 */
@@ -640,9 +999,8 @@
640 999 */
641 1000
642 1001
643 1002
644 -
645 1003 /**
646 1004 * Internal dependencies
647 1005 */
648 1006
@@ -652,39 +1010,31 @@
652 1010
653 1011 /**
654 1012 * Edit callback for language switcher block.
655 1013 *
656 - * @param {Object} props Block properties.
1014 + * @param {Object} props Block properties.
1015 + * @param {Object} props.attributes Block attributes.
1016 + * @param {Function} props.setAttributes Function to set block attributes.
657 1017 * @return {ReactElement} The block content and controls.
658 1018 */
659 1019
660 -const Edit = props => {
661 - const {
662 - dropdown
663 - } = props.attributes;
1020 +const Edit = ({
1021 + attributes,
1022 + setAttributes
1023 +}) => {
664 1024 const languages = useLanguagesList();
665 - const {
666 - ToggleControlDropdown,
667 - ToggleControlShowNames,
668 - ToggleControlShowFlags,
669 - ToggleControlForceHome,
670 - ToggleControlHideCurrent,
671 - ToggleControlHideIfNoTranslations
672 - } = createLanguageSwitcherEdit(props);
673 - return /*#__PURE__*/(0,jsx_runtime.jsxs)("div", {
1025 + return /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsxs)("div", {
674 1026 ...(0,external_this_wp_blockEditor_.useBlockProps)(),
675 - children: [/*#__PURE__*/(0,jsx_runtime.jsx)(external_this_wp_blockEditor_.InspectorControls, {
676 - children: /*#__PURE__*/(0,jsx_runtime.jsxs)(external_this_wp_components_.PanelBody, {
677 - title: (0,external_this_wp_i18n_.__)('Language switcher settings', 'polylang'),
678 - children: [/*#__PURE__*/(0,jsx_runtime.jsx)(ToggleControlDropdown, {}), !dropdown && /*#__PURE__*/(0,jsx_runtime.jsx)(ToggleControlShowNames, {}), !dropdown && /*#__PURE__*/(0,jsx_runtime.jsx)(ToggleControlShowFlags, {}), /*#__PURE__*/(0,jsx_runtime.jsx)(ToggleControlForceHome, {}), !dropdown && /*#__PURE__*/(0,jsx_runtime.jsx)(ToggleControlHideCurrent, {}), /*#__PURE__*/(0,jsx_runtime.jsx)(ToggleControlHideIfNoTranslations, {})]
679 - })
680 - }), /*#__PURE__*/(0,jsx_runtime.jsx)(external_this_wp_components_.Disabled, {
681 - children: /*#__PURE__*/(0,jsx_runtime.jsx)(LanguagesContext.Provider, {
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, {
682 1032 value: {
683 1033 languages
684 1034 },
685 - children: /*#__PURE__*/(0,jsx_runtime.jsx)(SwitcherContainer, {
686 - attributes: props.attributes
1035 + children: /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(RenderedSwitcher, {
1036 + attributes: attributes
687 1037 })
688 1038 })
689 1039 })]
690 1040 });
@@ -706,123 +1056,89 @@
706 1056 */
707 1057
708 1058
709 1059
1060 +
710 1061 (0,external_this_wp_blocks_.registerBlockType)(block_namespaceObject.UU, {
711 1062 icon: icons_translation,
712 - edit: Edit
1063 + edit: Edit,
1064 + deprecated: deprecated
713 1065 });
714 1066 // EXTERNAL MODULE: external {"this":["wp","hooks"]}
715 1067 var external_this_wp_hooks_ = __webpack_require__(873);
716 -;// ./js/src/blocks/navigation-language-switcher/components/switcher-link-element.js
1068 +;// ./js/src/blocks/navigation-language-switcher/deprecated.js
717 1069 /**
718 - * Internal dependencies
1070 + * Deprecated navigation language switcher block.
719 1071 */
720 1072
721 -
722 -/**
723 - * Switcher link element component.
724 - *
725 - * @param {Object} props Component props.
726 - * @param {Object} props.language Language object.
727 - * @param {boolean} props.isTopLevel Whether the language is the top level language.
728 - * @param {boolean} props.showFlags Whether to show the flags.
729 - * @param {boolean} props.showNames Whether to show the names.
730 - * @return {ReactElement} The Switcher element component.
731 - */
732 -
733 -const SwitcherLinkElement = ({
734 - language,
735 - isTopLevel,
736 - showFlags,
737 - showNames
738 -}) => {
739 - const {
740 - text,
741 - flag
742 - } = useMemoizedSwitcherLabel(language, showFlags, showNames);
743 - const prefix = isTopLevel ? '' : ' ';
744 - return (
745 - /*#__PURE__*/
746 - // eslint-disable-next-line jsx-a11y/anchor-is-valid
747 - (0,jsx_runtime.jsxs)("a", {
748 - href: '#',
749 - children: [prefix, /*#__PURE__*/(0,jsx_runtime.jsx)("span", {
750 - dangerouslySetInnerHTML: {
751 - __html: flag
752 - }
753 - }), " ", text, " "]
754 - })
755 - );
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: ''
756 1085 };
757 -;// ./node_modules/@wpsyntex/polylang-react-library/build/icons/submenu.js
758 -/**
759 - * Submenu icon
760 - */
761 -
762 -/**
763 - * WordPress dependencies
764 - */
765 -
766 -
767 -const submenu_isPrimitivesComponents = 'undefined' !== typeof wp.primitives;
768 -const SubmenuIcon = () => submenu_isPrimitivesComponents ? /*#__PURE__*/(0,jsx_runtime.jsx)(external_this_wp_primitives_.SVG, {
769 - xmlns: "http://www.w3.org/2000/svg",
770 - width: "12",
771 - height: "12",
772 - viewBox: "0 0 12 12",
773 - fill: "none",
774 - children: /*#__PURE__*/(0,jsx_runtime.jsx)(external_this_wp_primitives_.Path, {
775 - d: "M1.50002 4L6.00002 8L10.5 4",
776 - strokeWidth: "1.5"
777 - })
778 -}) : 'submenu';
779 -/* harmony default export */ const submenu = (SubmenuIcon);
780 -;// ./js/src/blocks/navigation-language-switcher/components/switcher-ui.js
781 -/**
782 - * WordPress dependencies
783 - */
784 -
785 -
786 -/**
787 - * Internal dependencies
788 - */
789 -
790 -
791 -
792 -/**
793 - * Switcher UI component.
794 - *
795 - * @param {Object} props The component props.
796 - * @param {Array} props.languages The languages to display.
797 - * @param {boolean} props.showFlags Whether to show the flags.
798 - * @param {boolean} props.showNames Whether to show the names.
799 - * @param {boolean} props.withSubmenuIcon Whether to show the submenu icon.
800 - * @return {ReactElement} The Switcher UI component.
801 - */
802 -
803 -const switcher_ui_SwitcherUI = ({
804 - languages,
805 - showFlags,
806 - showNames,
807 - withSubmenuIcon
808 -}) => {
809 - return /*#__PURE__*/(0,jsx_runtime.jsx)(jsx_runtime.Fragment, {
810 - children: languages && languages.map(language => {
811 - return /*#__PURE__*/(0,jsx_runtime.jsxs)(external_this_wp_element_.Fragment, {
812 - children: [/*#__PURE__*/(0,jsx_runtime.jsx)(SwitcherLinkElement, {
813 - language: language,
814 - isTopLevel: languages.indexOf(language) === 0,
815 - showFlags: showFlags,
816 - showNames: showNames
817 - }), withSubmenuIcon && /*#__PURE__*/(0,jsx_runtime.jsx)("span", {
818 - className: "wp-block-navigation__submenu-icon",
819 - children: /*#__PURE__*/(0,jsx_runtime.jsx)(submenu, {})
820 - })]
821 - }, language.slug);
822 - })
823 - });
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 + }
824 1139 };
1140 +/* harmony default export */ const navigation_language_switcher_deprecated = ([deprecated_v1]);
825 1141 // EXTERNAL MODULE: external {"this":["wp","editor"]}
826 1142 var external_this_wp_editor_ = __webpack_require__(2);
827 1143 ;// ./node_modules/@wpsyntex/polylang-react-library/build/hooks/use-current-language.js
828 1144 /**
@@ -850,9 +1166,9 @@
850 1166 return language.slug === currentLanguageSlug;
851 1167 });
852 1168 return currentLanguage ? currentLanguage : null;
853 1169 };
854 -;// ./js/src/blocks/navigation-language-switcher/components/navigation-switcher-container.js
1170 +;// ./js/src/blocks/navigation-language-switcher/rendered-switcher.js
855 1171 /**
856 1172 * WordPress dependencies
857 1173 */
858 1174
@@ -857,8 +1173,13 @@
857 1173 */
858 1174
859 1175
860 1176 /**
1177 + * External dependencies
1178 + */
1179 +
1180 +
1181 +/**
861 1182 * Internal dependencies
862 1183 */
863 1184
864 1185
@@ -864,24 +1185,27 @@
864 1185
865 1186
866 1187
867 1188 /**
868 - * Switcher container component.
1189 + * Rendered switcher component.
869 1190 *
870 1191 * @param {Object} props The component props.
871 1192 * @param {Object} props.attributes The block attributes.
872 1193 * @param {Object} props.context The block context.
873 - * @return {ReactElement} The Switcher component.
1194 + * @return {ReactElement} The rendered switcher.
874 1195 */
875 1196
876 -const NavigationSwitcherContainer = ({
1197 +const rendered_switcher_RenderedSwitcher = ({
877 1198 attributes,
878 1199 context
879 1200 }) => {
880 1201 const {
881 - dropdown,
1202 + layout,
1203 + show_labels,
882 1204 show_flags,
883 - show_names
1205 + flag_border_radius,
1206 + flag_width,
1207 + flag_label_spacing
884 1208 } = attributes;
885 1209 const {
886 1210 showSubmenuIcon,
887 1211 openSubmenusOnClick
@@ -889,14 +1213,31 @@
889 1213 const {
890 1214 languages
891 1215 } = (0,external_this_wp_element_.useContext)(LanguagesContext);
892 1216 const currentLanguage = useCurrentLanguage(languages);
893 - const curatedLanguages = useCuratedLanguages(languages, currentLanguage, dropdown);
894 - return /*#__PURE__*/(0,jsx_runtime.jsx)(switcher_ui_SwitcherUI, {
895 - languages: curatedLanguages,
896 - showFlags: Boolean(show_flags),
897 - showNames: Boolean(show_names),
898 - withSubmenuIcon: Boolean((showSubmenuIcon || openSubmenusOnClick) && dropdown)
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 + })
899 1240 });
900 1241 };
901 1242 ;// ./js/src/blocks/navigation-language-switcher/edit.js
902 1243 /**
@@ -908,9 +1249,8 @@
908 1249 */
909 1250
910 1251
911 1252
912 -
913 1253 /**
914 1254 * Internal dependencies
915 1255 */
916 1256
@@ -920,40 +1260,42 @@
920 1260
921 1261 /**
922 1262 * Edit callback for navigation language switcher block.
923 1263 *
924 - * @param {Object} props Block properties.
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.
925 1268 * @return {ReactElement} The block content and controls.
926 1269 */
927 1270
928 -const edit_Edit = props => {
929 - const {
930 - dropdown
931 - } = props.attributes;
1271 +const edit_Edit = ({
1272 + attributes,
1273 + context,
1274 + setAttributes
1275 +}) => {
932 1276 const languages = useLanguagesList();
933 1277 const {
934 - ToggleControlDropdown,
935 - ToggleControlShowNames,
936 - ToggleControlShowFlags,
937 - ToggleControlForceHome,
938 - ToggleControlHideCurrent,
939 - ToggleControlHideIfNoTranslations
940 - } = createLanguageSwitcherEdit(props);
941 - return /*#__PURE__*/(0,jsx_runtime.jsxs)("div", {
942 - ...(0,external_this_wp_blockEditor_.useBlockProps)(),
943 - children: [/*#__PURE__*/(0,jsx_runtime.jsx)(external_this_wp_blockEditor_.InspectorControls, {
944 - children: /*#__PURE__*/(0,jsx_runtime.jsxs)(external_this_wp_components_.PanelBody, {
945 - title: (0,external_this_wp_i18n_.__)('Language switcher settings', 'polylang'),
946 - children: [/*#__PURE__*/(0,jsx_runtime.jsx)(ToggleControlDropdown, {}), /*#__PURE__*/(0,jsx_runtime.jsx)(ToggleControlShowNames, {}), /*#__PURE__*/(0,jsx_runtime.jsx)(ToggleControlShowFlags, {}), /*#__PURE__*/(0,jsx_runtime.jsx)(ToggleControlForceHome, {}), !dropdown && /*#__PURE__*/(0,jsx_runtime.jsx)(ToggleControlHideCurrent, {}), /*#__PURE__*/(0,jsx_runtime.jsx)(ToggleControlHideIfNoTranslations, {})]
947 - })
948 - }), /*#__PURE__*/(0,jsx_runtime.jsx)(external_this_wp_components_.Disabled, {
949 - children: /*#__PURE__*/(0,jsx_runtime.jsx)(LanguagesContext.Provider, {
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, {
950 1292 value: {
951 1293 languages
952 1294 },
953 - children: /*#__PURE__*/(0,jsx_runtime.jsx)(NavigationSwitcherContainer, {
954 - attributes: props.attributes,
955 - context: props.context
1295 + children: /*#__PURE__*/(0,react_jsx_runtime_production_min_namespaceFn().jsx)(rendered_switcher_RenderedSwitcher, {
1296 + attributes: attributes,
1297 + context: context
956 1298 })
957 1299 })
958 1300 })]
959 1301 });
@@ -1047,8 +1389,9 @@
1047 1389
1048 1390
1049 1391
1050 1392
1393 +
1051 1394 (0,external_this_wp_blocks_.registerBlockType)(Navigation_block_namespaceObject.UU, {
1052 1395 icon: icons_translation,
1053 1396 transforms: {
1054 1397 from: [{
@@ -1056,9 +1399,10 @@
1056 1399 blocks: ['core/navigation-link'],
1057 1400 transform: () => (0,external_this_wp_blocks_.createBlock)(Navigation_block_namespaceObject.UU)
1058 1401 }]
1059 1402 },
1060 - edit: edit_Edit
1403 + edit: edit_Edit,
1404 + deprecated: navigation_language_switcher_deprecated
1061 1405 });
1062 1406
1063 1407 /**
1064 1408 * Hooks to the classic menu conversion to core/navigation block to be able to convert