[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/js/dist/ -> preferences.js (source)

   1  (function() {
   2  "use strict";
   3  var wp;
   4  (wp ||= {}).preferences = (() => {
   5    var __create = Object.create;
   6    var __defProp = Object.defineProperty;
   7    var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
   8    var __getOwnPropNames = Object.getOwnPropertyNames;
   9    var __getProtoOf = Object.getPrototypeOf;
  10    var __hasOwnProp = Object.prototype.hasOwnProperty;
  11    var __commonJS = (cb, mod) => function __require() {
  12      return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
  13    };
  14    var __export = (target, all) => {
  15      for (var name in all)
  16        __defProp(target, name, { get: all[name], enumerable: true });
  17    };
  18    var __copyProps = (to, from, except, desc) => {
  19      if (from && typeof from === "object" || typeof from === "function") {
  20        for (let key of __getOwnPropNames(from))
  21          if (!__hasOwnProp.call(to, key) && key !== except)
  22            __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  23      }
  24      return to;
  25    };
  26    var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  27      // If the importer is in node compatibility mode or this is not an ESM
  28      // file that has been converted to a CommonJS file using a Babel-
  29      // compatible transform (i.e. "__esModule" has not been set), then set
  30      // "default" to the CommonJS "module.exports" for node compatibility.
  31      isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  32      mod
  33    ));
  34    var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  35  
  36    // package-external:@wordpress/data
  37    var require_data = __commonJS({
  38      "package-external:@wordpress/data"(exports, module) {
  39        module.exports = window.wp.data;
  40      }
  41    });
  42  
  43    // package-external:@wordpress/components
  44    var require_components = __commonJS({
  45      "package-external:@wordpress/components"(exports, module) {
  46        module.exports = window.wp.components;
  47      }
  48    });
  49  
  50    // package-external:@wordpress/i18n
  51    var require_i18n = __commonJS({
  52      "package-external:@wordpress/i18n"(exports, module) {
  53        module.exports = window.wp.i18n;
  54      }
  55    });
  56  
  57    // package-external:@wordpress/element
  58    var require_element = __commonJS({
  59      "package-external:@wordpress/element"(exports, module) {
  60        module.exports = window.wp.element;
  61      }
  62    });
  63  
  64    // package-external:@wordpress/primitives
  65    var require_primitives = __commonJS({
  66      "package-external:@wordpress/primitives"(exports, module) {
  67        module.exports = window.wp.primitives;
  68      }
  69    });
  70  
  71    // vendor-external:react/jsx-runtime
  72    var require_jsx_runtime = __commonJS({
  73      "vendor-external:react/jsx-runtime"(exports, module) {
  74        module.exports = window.ReactJSXRuntime;
  75      }
  76    });
  77  
  78    // package-external:@wordpress/a11y
  79    var require_a11y = __commonJS({
  80      "package-external:@wordpress/a11y"(exports, module) {
  81        module.exports = window.wp.a11y;
  82      }
  83    });
  84  
  85    // package-external:@wordpress/deprecated
  86    var require_deprecated = __commonJS({
  87      "package-external:@wordpress/deprecated"(exports, module) {
  88        module.exports = window.wp.deprecated;
  89      }
  90    });
  91  
  92    // package-external:@wordpress/compose
  93    var require_compose = __commonJS({
  94      "package-external:@wordpress/compose"(exports, module) {
  95        module.exports = window.wp.compose;
  96      }
  97    });
  98  
  99    // package-external:@wordpress/private-apis
 100    var require_private_apis = __commonJS({
 101      "package-external:@wordpress/private-apis"(exports, module) {
 102        module.exports = window.wp.privateApis;
 103      }
 104    });
 105  
 106    // packages/preferences/build-module/index.mjs
 107    var index_exports = {};
 108    __export(index_exports, {
 109      PreferenceToggleMenuItem: () => PreferenceToggleMenuItem,
 110      privateApis: () => privateApis,
 111      store: () => store
 112    });
 113  
 114    // packages/preferences/build-module/components/preference-toggle-menu-item/index.mjs
 115    var import_data3 = __toESM(require_data(), 1);
 116    var import_components = __toESM(require_components(), 1);
 117    var import_i18n = __toESM(require_i18n(), 1);
 118  
 119    // packages/icons/build-module/icon/index.mjs
 120    var import_element = __toESM(require_element(), 1);
 121    var icon_default = (0, import_element.forwardRef)(
 122      ({ icon, size = 24, ...props }, ref) => {
 123        return (0, import_element.cloneElement)(icon, {
 124          width: size,
 125          height: size,
 126          ...props,
 127          ref
 128        });
 129      }
 130    );
 131  
 132    // packages/icons/build-module/library/check.mjs
 133    var import_primitives = __toESM(require_primitives(), 1);
 134    var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
 135    var check_default = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_primitives.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", fill: "currentColor", 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" }) });
 136  
 137    // packages/icons/build-module/library/chevron-left.mjs
 138    var import_primitives2 = __toESM(require_primitives(), 1);
 139    var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
 140    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", fill: "currentColor", 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" }) });
 141  
 142    // packages/icons/build-module/library/chevron-right.mjs
 143    var import_primitives3 = __toESM(require_primitives(), 1);
 144    var import_jsx_runtime3 = __toESM(require_jsx_runtime(), 1);
 145    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", fill: "currentColor", 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" }) });
 146  
 147    // packages/preferences/build-module/components/preference-toggle-menu-item/index.mjs
 148    var import_a11y = __toESM(require_a11y(), 1);
 149  
 150    // packages/preferences/build-module/store/index.mjs
 151    var import_data2 = __toESM(require_data(), 1);
 152  
 153    // packages/preferences/build-module/store/reducer.mjs
 154    var import_data = __toESM(require_data(), 1);
 155    function defaults(state = {}, action) {
 156      if (action.type === "SET_PREFERENCE_DEFAULTS") {
 157        const { scope, defaults: values } = action;
 158        return {
 159          ...state,
 160          [scope]: {
 161            ...state[scope],
 162            ...values
 163          }
 164        };
 165      }
 166      return state;
 167    }
 168    function withPersistenceLayer(reducer) {
 169      let persistenceLayer;
 170      return (state, action) => {
 171        if (action.type === "SET_PERSISTENCE_LAYER") {
 172          const { persistenceLayer: persistence, persistedData } = action;
 173          persistenceLayer = persistence;
 174          return persistedData;
 175        }
 176        const nextState = reducer(state, action);
 177        if (action.type === "SET_PREFERENCE_VALUE") {
 178          persistenceLayer?.set(nextState);
 179        }
 180        return nextState;
 181      };
 182    }
 183    var preferences = withPersistenceLayer((state = {}, action) => {
 184      if (action.type === "SET_PREFERENCE_VALUE") {
 185        const { scope, name, value } = action;
 186        return {
 187          ...state,
 188          [scope]: {
 189            ...state[scope],
 190            [name]: value
 191          }
 192        };
 193      }
 194      return state;
 195    });
 196    var reducer_default = (0, import_data.combineReducers)({
 197      defaults,
 198      preferences
 199    });
 200  
 201    // packages/preferences/build-module/store/actions.mjs
 202    var actions_exports = {};
 203    __export(actions_exports, {
 204      set: () => set,
 205      setDefaults: () => setDefaults,
 206      setPersistenceLayer: () => setPersistenceLayer,
 207      toggle: () => toggle
 208    });
 209    function toggle(scope, name) {
 210      return function({ select, dispatch }) {
 211        const currentValue = select.get(scope, name);
 212        dispatch.set(scope, name, !currentValue);
 213      };
 214    }
 215    function set(scope, name, value) {
 216      return {
 217        type: "SET_PREFERENCE_VALUE",
 218        scope,
 219        name,
 220        value
 221      };
 222    }
 223    function setDefaults(scope, defaults2) {
 224      return {
 225        type: "SET_PREFERENCE_DEFAULTS",
 226        scope,
 227        defaults: defaults2
 228      };
 229    }
 230    async function setPersistenceLayer(persistenceLayer) {
 231      const persistedData = await persistenceLayer.get();
 232      return {
 233        type: "SET_PERSISTENCE_LAYER",
 234        persistenceLayer,
 235        persistedData
 236      };
 237    }
 238  
 239    // packages/preferences/build-module/store/selectors.mjs
 240    var selectors_exports = {};
 241    __export(selectors_exports, {
 242      get: () => get
 243    });
 244    var import_deprecated = __toESM(require_deprecated(), 1);
 245    var withDeprecatedKeys = (originalGet) => (state, scope, name) => {
 246      const settingsToMoveToCore = [
 247        "allowRightClickOverrides",
 248        "distractionFree",
 249        "editorMode",
 250        "fixedToolbar",
 251        "focusMode",
 252        "hiddenBlockTypes",
 253        "inactivePanels",
 254        "keepCaretInsideBlock",
 255        "mostUsedBlocks",
 256        "openPanels",
 257        "showBlockBreadcrumbs",
 258        "showIconLabels",
 259        "showListViewByDefault",
 260        "isPublishSidebarEnabled",
 261        "isComplementaryAreaVisible",
 262        "pinnedItems"
 263      ];
 264      if (settingsToMoveToCore.includes(name) && ["core/edit-post", "core/edit-site"].includes(scope)) {
 265        (0, import_deprecated.default)(
 266          `wp.data.select( 'core/preferences' ).get( '$scope}', '$name}' )`,
 267          {
 268            since: "6.5",
 269            alternative: `wp.data.select( 'core/preferences' ).get( 'core', '$name}' )`
 270          }
 271        );
 272        return originalGet(state, "core", name);
 273      }
 274      return originalGet(state, scope, name);
 275    };
 276    var get = withDeprecatedKeys(
 277      (state, scope, name) => {
 278        const value = state.preferences[scope]?.[name];
 279        return value !== void 0 ? value : state.defaults[scope]?.[name];
 280      }
 281    );
 282  
 283    // packages/preferences/build-module/store/constants.mjs
 284    var STORE_NAME = "core/preferences";
 285  
 286    // packages/preferences/build-module/store/index.mjs
 287    var store = (0, import_data2.createReduxStore)(STORE_NAME, {
 288      reducer: reducer_default,
 289      actions: actions_exports,
 290      selectors: selectors_exports
 291    });
 292    (0, import_data2.register)(store);
 293  
 294    // packages/preferences/build-module/components/preference-toggle-menu-item/index.mjs
 295    var import_jsx_runtime4 = __toESM(require_jsx_runtime(), 1);
 296    function PreferenceToggleMenuItem({
 297      scope,
 298      name,
 299      label,
 300      info,
 301      messageActivated,
 302      messageDeactivated,
 303      shortcut,
 304      handleToggling = true,
 305      onToggle = () => null,
 306      disabled = false
 307    }) {
 308      const isActive = (0, import_data3.useSelect)(
 309        (select) => !!select(store).get(scope, name),
 310        [scope, name]
 311      );
 312      const { toggle: toggle2 } = (0, import_data3.useDispatch)(store);
 313      const speakMessage = () => {
 314        if (isActive) {
 315          const message = messageDeactivated || (0, import_i18n.sprintf)(
 316            /* translators: %s: preference name, e.g. 'Fullscreen mode' */
 317            (0, import_i18n.__)("Preference deactivated - %s"),
 318            label
 319          );
 320          (0, import_a11y.speak)(message);
 321        } else {
 322          const message = messageActivated || (0, import_i18n.sprintf)(
 323            /* translators: %s: preference name, e.g. 'Fullscreen mode' */
 324            (0, import_i18n.__)("Preference activated - %s"),
 325            label
 326          );
 327          (0, import_a11y.speak)(message);
 328        }
 329      };
 330      return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
 331        import_components.MenuItem,
 332        {
 333          icon: isActive ? check_default : null,
 334          isSelected: isActive,
 335          onClick: () => {
 336            onToggle();
 337            if (handleToggling) {
 338              toggle2(scope, name);
 339            }
 340            speakMessage();
 341          },
 342          role: "menuitemcheckbox",
 343          info,
 344          shortcut,
 345          disabled,
 346          children: label
 347        }
 348      );
 349    }
 350  
 351    // packages/preferences/build-module/components/preference-base-option/index.mjs
 352    var import_components2 = __toESM(require_components(), 1);
 353    var import_jsx_runtime5 = __toESM(require_jsx_runtime(), 1);
 354    function BaseOption({
 355      help,
 356      label,
 357      isChecked,
 358      onChange,
 359      children
 360    }) {
 361      return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "preference-base-option", children: [
 362        /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
 363          import_components2.ToggleControl,
 364          {
 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.mjs
 377    var import_data4 = __toESM(require_data(), 1);
 378    var import_jsx_runtime6 = __toESM(require_jsx_runtime(), 1);
 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.mjs
 408    var import_components3 = __toESM(require_components(), 1);
 409    var import_i18n2 = __toESM(require_i18n(), 1);
 410    var import_jsx_runtime7 = __toESM(require_jsx_runtime(), 1);
 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.mjs
 427    var import_jsx_runtime8 = __toESM(require_jsx_runtime(), 1);
 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.mjs
 438    var import_compose = __toESM(require_compose(), 1);
 439    var import_components4 = __toESM(require_components(), 1);
 440    var import_element2 = __toESM(require_element(), 1);
 441    var import_i18n3 = __toESM(require_i18n(), 1);
 442  
 443    // packages/preferences/build-module/lock-unlock.mjs
 444    var import_private_apis = __toESM(require_private_apis(), 1);
 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.mjs
 451    var import_jsx_runtime9 = __toESM(require_jsx_runtime(), 1);
 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 /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
 511              import_components4.Navigator.Button,
 512              {
 513                path: `/$tab.name}`,
 514                as: import_components4.__experimentalItem,
 515                isAction: true,
 516                children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_components4.__experimentalHStack, { justify: "space-between", children: [
 517                  /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_components4.FlexItem, { children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_components4.__experimentalTruncate, { children: tab.title }) }),
 518                  /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_components4.FlexItem, { children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
 519                    icon_default,
 520                    {
 521                      icon: (0, import_i18n3.isRTL)() ? chevron_left_default : chevron_right_default
 522                    }
 523                  ) })
 524                ] })
 525              },
 526              tab.name
 527            );
 528          }) }) }) }) }),
 529          sections.length && sections.map((section) => {
 530            return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
 531              import_components4.Navigator.Screen,
 532              {
 533                path: `/$section.name}`,
 534                children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_components4.Card, { isBorderless: true, size: "large", children: [
 535                  /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
 536                    import_components4.CardHeader,
 537                    {
 538                      isBorderless: false,
 539                      justify: "left",
 540                      size: "small",
 541                      gap: "6",
 542                      as: "div",
 543                      children: [
 544                        /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
 545                          import_components4.Navigator.BackButton,
 546                          {
 547                            icon: (0, import_i18n3.isRTL)() ? chevron_right_default : chevron_left_default,
 548                            label: (0, import_i18n3.__)("Back")
 549                          }
 550                        ),
 551                        /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_components4.__experimentalText, { size: "16", children: section.tabLabel })
 552                      ]
 553                    }
 554                  ),
 555                  /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_components4.CardBody, { children: section.content })
 556                ] })
 557              },
 558              `$section.name}-menu`
 559            );
 560          })
 561        ] });
 562      }
 563      return modalContent;
 564    }
 565  
 566    // packages/preferences/build-module/private-apis.mjs
 567    var privateApis = {};
 568    lock(privateApis, {
 569      PreferenceBaseOption: preference_base_option_default,
 570      PreferenceToggleControl: preference_toggle_control_default,
 571      PreferencesModal,
 572      PreferencesModalSection: preferences_modal_section_default,
 573      PreferencesModalTabs
 574    });
 575    return __toCommonJS(index_exports);
 576  })();
 577  (window.wp ||= {}).preferences = wp.preferences;
 578  })();


Generated : Tue Aug 25 08:20:24 2026 Cross-referenced by PHPXref