PluginProbe
Gutenberg / 22.3.0
Gutenberg v22.3.0
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / build / scripts / preferences / index.js

index.js in Gutenberg 22.3.0, at build/scripts/preferences/index.js

581 lines 21.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 "use strict";
2 var wp;
3 (wp ||= {}).preferences = (() => {
4 var __create = Object.create;
5 var __defProp = Object.defineProperty;
6 var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7 var __getOwnPropNames = Object.getOwnPropertyNames;
8 var __getProtoOf = Object.getPrototypeOf;
9 var __hasOwnProp = Object.prototype.hasOwnProperty;
10 var __commonJS = (cb, mod) => function __require() {
11 return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
12 };
13 var __export = (target, all) => {
14 for (var name in all)
15 __defProp(target, name, { get: all[name], enumerable: true });
16 };
17 var __copyProps = (to, from, except, desc) => {
18 if (from && typeof from === "object" || typeof from === "function") {
19 for (let key of __getOwnPropNames(from))
20 if (!__hasOwnProp.call(to, key) && key !== except)
21 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22 }
23 return to;
24 };
25 var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
26 // If the importer is in node compatibility mode or this is not an ESM
27 // file that has been converted to a CommonJS file using a Babel-
28 // compatible transform (i.e. "__esModule" has not been set), then set
29 // "default" to the CommonJS "module.exports" for node compatibility.
30 isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
31 mod
32 ));
33 var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
34
35 // package-external:@wordpress/data
36 var require_data = __commonJS({
37 "package-external:@wordpress/data"(exports, module) {
38 module.exports = window.wp.data;
39 }
40 });
41
42 // package-external:@wordpress/components
43 var require_components = __commonJS({
44 "package-external:@wordpress/components"(exports, module) {
45 module.exports = window.wp.components;
46 }
47 });
48
49 // package-external:@wordpress/i18n
50 var require_i18n = __commonJS({
51 "package-external:@wordpress/i18n"(exports, module) {
52 module.exports = window.wp.i18n;
53 }
54 });
55
56 // package-external:@wordpress/element
57 var require_element = __commonJS({
58 "package-external:@wordpress/element"(exports, module) {
59 module.exports = window.wp.element;
60 }
61 });
62
63 // package-external:@wordpress/primitives
64 var require_primitives = __commonJS({
65 "package-external:@wordpress/primitives"(exports, module) {
66 module.exports = window.wp.primitives;
67 }
68 });
69
70 // vendor-external:react/jsx-runtime
71 var require_jsx_runtime = __commonJS({
72 "vendor-external:react/jsx-runtime"(exports, module) {
73 module.exports = window.ReactJSXRuntime;
74 }
75 });
76
77 // package-external:@wordpress/a11y
78 var require_a11y = __commonJS({
79 "package-external:@wordpress/a11y"(exports, module) {
80 module.exports = window.wp.a11y;
81 }
82 });
83
84 // package-external:@wordpress/deprecated
85 var require_deprecated = __commonJS({
86 "package-external:@wordpress/deprecated"(exports, module) {
87 module.exports = window.wp.deprecated;
88 }
89 });
90
91 // package-external:@wordpress/compose
92 var require_compose = __commonJS({
93 "package-external:@wordpress/compose"(exports, module) {
94 module.exports = window.wp.compose;
95 }
96 });
97
98 // package-external:@wordpress/private-apis
99 var require_private_apis = __commonJS({
100 "package-external:@wordpress/private-apis"(exports, module) {
101 module.exports = window.wp.privateApis;
102 }
103 });
104
105 // packages/preferences/build-module/index.js
106 var index_exports = {};
107 __export(index_exports, {
108 PreferenceToggleMenuItem: () => PreferenceToggleMenuItem,
109 privateApis: () => privateApis,
110 store: () => store
111 });
112
113 // packages/preferences/build-module/components/preference-toggle-menu-item/index.js
114 var import_data3 = __toESM(require_data());
115 var import_components = __toESM(require_components());
116 var import_i18n = __toESM(require_i18n());
117
118 // packages/icons/build-module/icon/index.js
119 var import_element = __toESM(require_element());
120 var icon_default = (0, import_element.forwardRef)(
121 ({ icon, size = 24, ...props }, ref) => {
122 return (0, import_element.cloneElement)(icon, {
123 width: size,
124 height: size,
125 ...props,
126 ref
127 });
128 }
129 );
130
131 // packages/icons/build-module/library/check.js
132 var import_primitives = __toESM(require_primitives());
133 var import_jsx_runtime = __toESM(require_jsx_runtime());
134 var check_default = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_primitives.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_primitives.Path, { d: "M16.5 7.5 10 13.9l-2.5-2.4-1 1 3.5 3.6 7.5-7.6z" }) });
135
136 // packages/icons/build-module/library/chevron-left.js
137 var import_primitives2 = __toESM(require_primitives());
138 var import_jsx_runtime2 = __toESM(require_jsx_runtime());
139 var chevron_left_default = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_primitives2.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_primitives2.Path, { d: "M14.6 7l-1.2-1L8 12l5.4 6 1.2-1-4.6-5z" }) });
140
141 // packages/icons/build-module/library/chevron-right.js
142 var import_primitives3 = __toESM(require_primitives());
143 var import_jsx_runtime3 = __toESM(require_jsx_runtime());
144 var chevron_right_default = /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_primitives3.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_primitives3.Path, { d: "M10.6 6L9.4 7l4.6 5-4.6 5 1.2 1 5.4-6z" }) });
145
146 // packages/preferences/build-module/components/preference-toggle-menu-item/index.js
147 var import_a11y = __toESM(require_a11y());
148
149 // packages/preferences/build-module/store/index.js
150 var import_data2 = __toESM(require_data());
151
152 // packages/preferences/build-module/store/reducer.js
153 var import_data = __toESM(require_data());
154 function defaults(state = {}, action) {
155 if (action.type === "SET_PREFERENCE_DEFAULTS") {
156 const { scope, defaults: values } = action;
157 return {
158 ...state,
159 [scope]: {
160 ...state[scope],
161 ...values
162 }
163 };
164 }
165 return state;
166 }
167 function withPersistenceLayer(reducer) {
168 let persistenceLayer;
169 return (state, action) => {
170 if (action.type === "SET_PERSISTENCE_LAYER") {
171 const { persistenceLayer: persistence, persistedData } = action;
172 persistenceLayer = persistence;
173 return persistedData;
174 }
175 const nextState = reducer(state, action);
176 if (action.type === "SET_PREFERENCE_VALUE") {
177 persistenceLayer?.set(nextState);
178 }
179 return nextState;
180 };
181 }
182 var preferences = withPersistenceLayer((state = {}, action) => {
183 if (action.type === "SET_PREFERENCE_VALUE") {
184 const { scope, name, value } = action;
185 return {
186 ...state,
187 [scope]: {
188 ...state[scope],
189 [name]: value
190 }
191 };
192 }
193 return state;
194 });
195 var reducer_default = (0, import_data.combineReducers)({
196 defaults,
197 preferences
198 });
199
200 // packages/preferences/build-module/store/actions.js
201 var actions_exports = {};
202 __export(actions_exports, {
203 set: () => set,
204 setDefaults: () => setDefaults,
205 setPersistenceLayer: () => setPersistenceLayer,
206 toggle: () => toggle
207 });
208 function toggle(scope, name) {
209 return function({ select, dispatch }) {
210 const currentValue = select.get(scope, name);
211 dispatch.set(scope, name, !currentValue);
212 };
213 }
214 function set(scope, name, value) {
215 return {
216 type: "SET_PREFERENCE_VALUE",
217 scope,
218 name,
219 value
220 };
221 }
222 function setDefaults(scope, defaults2) {
223 return {
224 type: "SET_PREFERENCE_DEFAULTS",
225 scope,
226 defaults: defaults2
227 };
228 }
229 async function setPersistenceLayer(persistenceLayer) {
230 const persistedData = await persistenceLayer.get();
231 return {
232 type: "SET_PERSISTENCE_LAYER",
233 persistenceLayer,
234 persistedData
235 };
236 }
237
238 // packages/preferences/build-module/store/selectors.js
239 var selectors_exports = {};
240 __export(selectors_exports, {
241 get: () => get
242 });
243 var import_deprecated = __toESM(require_deprecated());
244 var withDeprecatedKeys = (originalGet) => (state, scope, name) => {
245 const settingsToMoveToCore = [
246 "allowRightClickOverrides",
247 "distractionFree",
248 "editorMode",
249 "fixedToolbar",
250 "focusMode",
251 "hiddenBlockTypes",
252 "inactivePanels",
253 "keepCaretInsideBlock",
254 "mostUsedBlocks",
255 "openPanels",
256 "showBlockBreadcrumbs",
257 "showIconLabels",
258 "showListViewByDefault",
259 "isPublishSidebarEnabled",
260 "isComplementaryAreaVisible",
261 "pinnedItems"
262 ];
263 if (settingsToMoveToCore.includes(name) && ["core/edit-post", "core/edit-site"].includes(scope)) {
264 (0, import_deprecated.default)(
265 `wp.data.select( 'core/preferences' ).get( '${scope}', '${name}' )`,
266 {
267 since: "6.5",
268 alternative: `wp.data.select( 'core/preferences' ).get( 'core', '${name}' )`
269 }
270 );
271 return originalGet(state, "core", name);
272 }
273 return originalGet(state, scope, name);
274 };
275 var get = withDeprecatedKeys(
276 (state, scope, name) => {
277 const value = state.preferences[scope]?.[name];
278 return value !== void 0 ? value : state.defaults[scope]?.[name];
279 }
280 );
281
282 // packages/preferences/build-module/store/constants.js
283 var STORE_NAME = "core/preferences";
284
285 // packages/preferences/build-module/store/index.js
286 var store = (0, import_data2.createReduxStore)(STORE_NAME, {
287 reducer: reducer_default,
288 actions: actions_exports,
289 selectors: selectors_exports
290 });
291 (0, import_data2.register)(store);
292
293 // packages/preferences/build-module/components/preference-toggle-menu-item/index.js
294 var import_jsx_runtime4 = __toESM(require_jsx_runtime());
295 function PreferenceToggleMenuItem({
296 scope,
297 name,
298 label,
299 info,
300 messageActivated,
301 messageDeactivated,
302 shortcut,
303 handleToggling = true,
304 onToggle = () => null,
305 disabled = false
306 }) {
307 const isActive = (0, import_data3.useSelect)(
308 (select) => !!select(store).get(scope, name),
309 [scope, name]
310 );
311 const { toggle: toggle2 } = (0, import_data3.useDispatch)(store);
312 const speakMessage = () => {
313 if (isActive) {
314 const message = messageDeactivated || (0, import_i18n.sprintf)(
315 /* translators: %s: preference name, e.g. 'Fullscreen mode' */
316 (0, import_i18n.__)("Preference deactivated - %s"),
317 label
318 );
319 (0, import_a11y.speak)(message);
320 } else {
321 const message = messageActivated || (0, import_i18n.sprintf)(
322 /* translators: %s: preference name, e.g. 'Fullscreen mode' */
323 (0, import_i18n.__)("Preference activated - %s"),
324 label
325 );
326 (0, import_a11y.speak)(message);
327 }
328 };
329 return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
330 import_components.MenuItem,
331 {
332 icon: isActive ? check_default : null,
333 isSelected: isActive,
334 onClick: () => {
335 onToggle();
336 if (handleToggling) {
337 toggle2(scope, name);
338 }
339 speakMessage();
340 },
341 role: "menuitemcheckbox",
342 info,
343 shortcut,
344 disabled,
345 children: label
346 }
347 );
348 }
349
350 // packages/preferences/build-module/components/preference-base-option/index.js
351 var import_components2 = __toESM(require_components());
352 var import_jsx_runtime5 = __toESM(require_jsx_runtime());
353 function BaseOption({
354 help,
355 label,
356 isChecked,
357 onChange,
358 children
359 }) {
360 return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "preference-base-option", children: [
361 /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
362 import_components2.ToggleControl,
363 {
364 __nextHasNoMarginBottom: true,
365 help,
366 label,
367 checked: isChecked,
368 onChange
369 }
370 ),
371 children
372 ] });
373 }
374 var preference_base_option_default = BaseOption;
375
376 // packages/preferences/build-module/components/preference-toggle-control/index.js
377 var import_data4 = __toESM(require_data());
378 var import_jsx_runtime6 = __toESM(require_jsx_runtime());
379 function PreferenceToggleControl(props) {
380 const {
381 scope,
382 featureName,
383 onToggle = () => {
384 },
385 ...remainingProps
386 } = props;
387 const isChecked = (0, import_data4.useSelect)(
388 (select) => !!select(store).get(scope, featureName),
389 [scope, featureName]
390 );
391 const { toggle: toggle2 } = (0, import_data4.useDispatch)(store);
392 const onChange = () => {
393 onToggle();
394 toggle2(scope, featureName);
395 };
396 return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
397 preference_base_option_default,
398 {
399 ...remainingProps,
400 onChange,
401 isChecked
402 }
403 );
404 }
405 var preference_toggle_control_default = PreferenceToggleControl;
406
407 // packages/preferences/build-module/components/preferences-modal/index.js
408 var import_components3 = __toESM(require_components());
409 var import_i18n2 = __toESM(require_i18n());
410 var import_jsx_runtime7 = __toESM(require_jsx_runtime());
411 function PreferencesModal({
412 closeModal,
413 children
414 }) {
415 return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
416 import_components3.Modal,
417 {
418 className: "preferences-modal",
419 title: (0, import_i18n2.__)("Preferences"),
420 onRequestClose: closeModal,
421 children
422 }
423 );
424 }
425
426 // packages/preferences/build-module/components/preferences-modal-section/index.js
427 var import_jsx_runtime8 = __toESM(require_jsx_runtime());
428 var Section = ({ description, title, children }) => /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("fieldset", { className: "preferences-modal__section", children: [
429 /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("legend", { className: "preferences-modal__section-legend", children: [
430 /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("h2", { className: "preferences-modal__section-title", children: title }),
431 description && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { className: "preferences-modal__section-description", children: description })
432 ] }),
433 /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "preferences-modal__section-content", children })
434 ] });
435 var preferences_modal_section_default = Section;
436
437 // packages/preferences/build-module/components/preferences-modal-tabs/index.js
438 var import_compose = __toESM(require_compose());
439 var import_components4 = __toESM(require_components());
440 var import_element2 = __toESM(require_element());
441 var import_i18n3 = __toESM(require_i18n());
442
443 // packages/preferences/build-module/lock-unlock.js
444 var import_private_apis = __toESM(require_private_apis());
445 var { lock, unlock } = (0, import_private_apis.__dangerousOptInToUnstableAPIsOnlyForCoreModules)(
446 "I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.",
447 "@wordpress/preferences"
448 );
449
450 // packages/preferences/build-module/components/preferences-modal-tabs/index.js
451 var import_jsx_runtime9 = __toESM(require_jsx_runtime());
452 var { Tabs } = unlock(import_components4.privateApis);
453 var PREFERENCES_MENU = "preferences-menu";
454 function PreferencesModalTabs({
455 sections
456 }) {
457 const isLargeViewport = (0, import_compose.useViewportMatch)("medium");
458 const [activeMenu, setActiveMenu] = (0, import_element2.useState)(PREFERENCES_MENU);
459 const { tabs, sectionsContentMap } = (0, import_element2.useMemo)(() => {
460 let mappedTabs = {
461 tabs: [],
462 sectionsContentMap: {}
463 };
464 if (sections.length) {
465 mappedTabs = sections.reduce(
466 (accumulator, { name, tabLabel: title, content }) => {
467 accumulator.tabs.push({ name, title });
468 accumulator.sectionsContentMap[name] = content;
469 return accumulator;
470 },
471 { tabs: [], sectionsContentMap: {} }
472 );
473 }
474 return mappedTabs;
475 }, [sections]);
476 let modalContent;
477 if (isLargeViewport) {
478 modalContent = /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "preferences__tabs", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
479 Tabs,
480 {
481 defaultTabId: activeMenu !== PREFERENCES_MENU ? activeMenu : void 0,
482 onSelect: setActiveMenu,
483 orientation: "vertical",
484 children: [
485 /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Tabs.TabList, { className: "preferences__tabs-tablist", children: tabs.map((tab) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
486 Tabs.Tab,
487 {
488 tabId: tab.name,
489 className: "preferences__tabs-tab",
490 children: tab.title
491 },
492 tab.name
493 )) }),
494 tabs.map((tab) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
495 Tabs.TabPanel,
496 {
497 tabId: tab.name,
498 className: "preferences__tabs-tabpanel",
499 focusable: false,
500 children: sectionsContentMap[tab.name] || null
501 },
502 tab.name
503 ))
504 ]
505 }
506 ) });
507 } else {
508 modalContent = /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_components4.Navigator, { initialPath: "/", className: "preferences__provider", children: [
509 /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_components4.Navigator.Screen, { path: "/", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_components4.Card, { isBorderless: true, size: "small", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_components4.CardBody, { children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_components4.__experimentalItemGroup, { children: tabs.map((tab) => {
510 return (
511 // @ts-expect-error: Navigator.Button is currently typed in a way that prevents Item from being passed in
512 /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
513 import_components4.Navigator.Button,
514 {
515 path: `/${tab.name}`,
516 as: import_components4.__experimentalItem,
517 isAction: true,
518 children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_components4.__experimentalHStack, { justify: "space-between", children: [
519 /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_components4.FlexItem, { children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_components4.__experimentalTruncate, { children: tab.title }) }),
520 /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_components4.FlexItem, { children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
521 icon_default,
522 {
523 icon: (0, import_i18n3.isRTL)() ? chevron_left_default : chevron_right_default
524 }
525 ) })
526 ] })
527 },
528 tab.name
529 )
530 );
531 }) }) }) }) }),
532 sections.length && sections.map((section) => {
533 return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
534 import_components4.Navigator.Screen,
535 {
536 path: `/${section.name}`,
537 children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_components4.Card, { isBorderless: true, size: "large", children: [
538 /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
539 import_components4.CardHeader,
540 {
541 isBorderless: false,
542 justify: "left",
543 size: "small",
544 gap: "6",
545 as: "div",
546 children: [
547 /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
548 import_components4.Navigator.BackButton,
549 {
550 icon: (0, import_i18n3.isRTL)() ? chevron_right_default : chevron_left_default,
551 label: (0, import_i18n3.__)("Back")
552 }
553 ),
554 /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_components4.__experimentalText, { size: "16", children: section.tabLabel })
555 ]
556 }
557 ),
558 /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_components4.CardBody, { children: section.content })
559 ] })
560 },
561 `${section.name}-menu`
562 );
563 })
564 ] });
565 }
566 return modalContent;
567 }
568
569 // packages/preferences/build-module/private-apis.js
570 var privateApis = {};
571 lock(privateApis, {
572 PreferenceBaseOption: preference_base_option_default,
573 PreferenceToggleControl: preference_toggle_control_default,
574 PreferencesModal,
575 PreferencesModalSection: preferences_modal_section_default,
576 PreferencesModalTabs
577 });
578 return __toCommonJS(index_exports);
579 })();
580 //# sourceMappingURL=index.js.map
581