@wordpress/preferences 3.26.0 → 3.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/preference-base-option/index.js +32 -0
  3. package/build/components/preference-base-option/index.js.map +1 -0
  4. package/build/components/preference-toggle-control/index.js +43 -0
  5. package/build/components/preference-toggle-control/index.js.map +1 -0
  6. package/build/components/preferences-modal/index.js +24 -0
  7. package/build/components/preferences-modal/index.js.map +1 -0
  8. package/build/components/preferences-modal-section/index.js +25 -0
  9. package/build/components/preferences-modal-section/index.js.map +1 -0
  10. package/build/components/preferences-modal-tabs/index.js +129 -0
  11. package/build/components/preferences-modal-tabs/index.js.map +1 -0
  12. package/build/index.js +12 -0
  13. package/build/index.js.map +1 -1
  14. package/build/lock-unlock.js +18 -0
  15. package/build/lock-unlock.js.map +1 -0
  16. package/build/private-apis.js +27 -0
  17. package/build/private-apis.js.map +1 -0
  18. package/build/store/index.js +1 -1
  19. package/build/store/index.js.map +1 -1
  20. package/build/store/selectors.js +22 -3
  21. package/build/store/selectors.js.map +1 -1
  22. package/build-module/components/preference-base-option/index.js +24 -0
  23. package/build-module/components/preference-base-option/index.js.map +1 -0
  24. package/build-module/components/preference-toggle-control/index.js +34 -0
  25. package/build-module/components/preference-toggle-control/index.js.map +1 -0
  26. package/build-module/components/preferences-modal/index.js +17 -0
  27. package/build-module/components/preferences-modal/index.js.map +1 -0
  28. package/build-module/components/preferences-modal-section/index.js +18 -0
  29. package/build-module/components/preferences-modal-section/index.js.map +1 -0
  30. package/build-module/components/preferences-modal-tabs/index.js +122 -0
  31. package/build-module/components/preferences-modal-tabs/index.js.map +1 -0
  32. package/build-module/index.js +1 -0
  33. package/build-module/index.js.map +1 -1
  34. package/build-module/lock-unlock.js +9 -0
  35. package/build-module/lock-unlock.js.map +1 -0
  36. package/build-module/private-apis.js +18 -0
  37. package/build-module/private-apis.js.map +1 -0
  38. package/build-module/store/index.js +1 -1
  39. package/build-module/store/index.js.map +1 -1
  40. package/build-module/store/selectors.js +18 -2
  41. package/build-module/store/selectors.js.map +1 -1
  42. package/build-style/style-rtl.css +199 -0
  43. package/build-style/style.css +199 -0
  44. package/package.json +11 -8
  45. package/src/components/preference-base-option/README.md +40 -0
  46. package/src/components/preference-base-option/index.js +21 -0
  47. package/src/components/preference-base-option/style.scss +10 -0
  48. package/src/components/preference-toggle-control/index.js +38 -0
  49. package/src/components/preferences-modal/README.md +69 -0
  50. package/src/components/preferences-modal/index.js +17 -0
  51. package/src/components/preferences-modal/style.scss +21 -0
  52. package/src/components/preferences-modal-section/README.md +31 -0
  53. package/src/components/preferences-modal-section/index.js +15 -0
  54. package/src/components/preferences-modal-section/style.scss +28 -0
  55. package/src/components/preferences-modal-tabs/README.md +14 -0
  56. package/src/components/preferences-modal-tabs/index.js +178 -0
  57. package/src/components/preferences-modal-tabs/style.scss +48 -0
  58. package/src/index.js +1 -0
  59. package/src/lock-unlock.js +9 -0
  60. package/src/private-apis.js +18 -0
  61. package/src/store/index.js +1 -1
  62. package/src/store/selectors.js +42 -2
  63. package/src/style.scss +4 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/preferences",
3
- "version": "3.26.0",
3
+ "version": "3.27.0",
4
4
  "description": "Utilities for managing WordPress preferences.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -29,12 +29,15 @@
29
29
  "sideEffects": false,
30
30
  "dependencies": {
31
31
  "@babel/runtime": "^7.16.0",
32
- "@wordpress/a11y": "^3.49.0",
33
- "@wordpress/components": "^25.15.0",
34
- "@wordpress/data": "^9.19.0",
35
- "@wordpress/element": "^5.26.0",
36
- "@wordpress/i18n": "^4.49.0",
37
- "@wordpress/icons": "^9.40.0",
32
+ "@wordpress/a11y": "^3.50.0",
33
+ "@wordpress/components": "^25.16.0",
34
+ "@wordpress/compose": "^6.27.0",
35
+ "@wordpress/data": "^9.20.0",
36
+ "@wordpress/deprecated": "^3.50.0",
37
+ "@wordpress/element": "^5.27.0",
38
+ "@wordpress/i18n": "^4.50.0",
39
+ "@wordpress/icons": "^9.41.0",
40
+ "@wordpress/private-apis": "^0.32.0",
38
41
  "classnames": "^2.3.1"
39
42
  },
40
43
  "peerDependencies": {
@@ -44,5 +47,5 @@
44
47
  "publishConfig": {
45
48
  "access": "public"
46
49
  },
47
- "gitHead": "5e6f9caa205d3bfdbac131952b7bf9c6ec60569b"
50
+ "gitHead": "45de2cb4212fed7f2763e95f10300d1ff9d0ec08"
48
51
  }
@@ -0,0 +1,40 @@
1
+ # PreferenceBaseOption
2
+
3
+ `PreferenceBaseOption` renders a toggle meant to be used within `PreferencesModal`.
4
+
5
+ This component implements a `ToggleControl` component from the `@wordpress/components` package.
6
+
7
+ ## Example
8
+
9
+ ```jsx
10
+ function MyEditorPreferencesOption() {
11
+ return (
12
+ <PreferenceBaseOption
13
+ label={ label }
14
+ isChecked={ isChecked }
15
+ onChange={ setIsChecked }
16
+ >
17
+ { isChecked !== areCustomFieldsEnabled && (
18
+ <CustomFieldsConfirmation willEnable={ isChecked } />
19
+ ) }
20
+ </PreferenceBaseOption>
21
+ )
22
+ }
23
+ ```
24
+
25
+ ## Props
26
+
27
+ ### help
28
+ ### label
29
+ ### isChecked
30
+ ### onChange
31
+
32
+ These props are passed directly to ToggleControl, so see [ToggleControl readme](https://github.com/WordPress/gutenberg/blob/trunk/packages/components/src/toggle-control/README.md) for more info.
33
+
34
+ ### children
35
+
36
+ Components to be rendered as content.
37
+
38
+ - Type: `Element`
39
+ - Required: No.
40
+
@@ -0,0 +1,21 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { ToggleControl } from '@wordpress/components';
5
+
6
+ function BaseOption( { help, label, isChecked, onChange, children } ) {
7
+ return (
8
+ <div className="preference-base-option">
9
+ <ToggleControl
10
+ __nextHasNoMarginBottom
11
+ help={ help }
12
+ label={ label }
13
+ checked={ isChecked }
14
+ onChange={ onChange }
15
+ />
16
+ { children }
17
+ </div>
18
+ );
19
+ }
20
+
21
+ export default BaseOption;
@@ -0,0 +1,10 @@
1
+ .preference-base-option {
2
+ & + & {
3
+ margin-top: $grid-unit-20;
4
+ }
5
+
6
+ .components-base-control__help {
7
+ margin-top: 0;
8
+ margin-left: 48px;
9
+ }
10
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { useSelect, useDispatch } from '@wordpress/data';
5
+
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+ import { store as preferencesStore } from '../../store';
10
+ import PreferenceBaseOption from '../preference-base-option';
11
+
12
+ function PreferenceToggleControl( props ) {
13
+ const {
14
+ scope,
15
+ featureName,
16
+ onToggle = () => {},
17
+ ...remainingProps
18
+ } = props;
19
+ const isChecked = useSelect(
20
+ ( select ) => !! select( preferencesStore ).get( scope, featureName ),
21
+ [ scope, featureName ]
22
+ );
23
+ const { toggle } = useDispatch( preferencesStore );
24
+ const onChange = () => {
25
+ onToggle();
26
+ toggle( scope, featureName );
27
+ };
28
+
29
+ return (
30
+ <PreferenceBaseOption
31
+ onChange={ onChange }
32
+ isChecked={ isChecked }
33
+ { ...remainingProps }
34
+ />
35
+ );
36
+ }
37
+
38
+ export default PreferenceToggleControl;
@@ -0,0 +1,69 @@
1
+ # PreferencesModal
2
+
3
+ `PreferencesModal` renders a modal with editor preferences. It can take a `PreferencesModalTabs` component, which accepts multiple tabs, and/or other child components. On small viewports, the modal is fullscreen.
4
+
5
+ This component implements a `Modal` component from the `@wordpress/components` package.
6
+
7
+ Sections passed to this component should use `PreferencesModalSection` component from the `@wordpress/preferences` package.
8
+
9
+
10
+ ## Example
11
+
12
+ ```jsx
13
+ function MyEditorPreferencesModal() {
14
+ const { closeModal } = useDispatch( editPostStore );
15
+ const sections = [
16
+ {
17
+ name: 'section 1',
18
+ tabLabel: __( 'Section 1' ),
19
+ content: (
20
+ <PreferencesModalSection
21
+ title={ __( 'Publishing' ) }
22
+ description={ __(
23
+ 'Change options related to publishing.'
24
+ ) }
25
+ >
26
+ <EnablePublishSidebarOption
27
+ help={ __(
28
+ 'Review settings, such as visibility and tags.'
29
+ ) }
30
+ label={ __(
31
+ 'Enable pre-publish checks'
32
+ ) }
33
+ />
34
+ </PreferencesModalSection>
35
+ )
36
+
37
+ }
38
+ {
39
+ name: 'section 2',
40
+ tabLabel: __( 'Section 2' ),
41
+ content: (
42
+ <PreferencesModalSection
43
+ title={ __( 'Additional' ) }
44
+ description={ __(
45
+ 'Add extra areas to the editor.'
46
+ ) }
47
+ >
48
+ // Section content here
49
+ </PreferencesModalSection>
50
+ )
51
+
52
+ }
53
+ ]
54
+ return (
55
+ <PreferencesModal closeModal={ closeModal }>
56
+ <PreferencesModalTabs sections={ sections } />
57
+ <PreferencesModal />
58
+ );
59
+ }
60
+ ```
61
+
62
+ ## Props
63
+
64
+ ### closeModal
65
+
66
+ A function to call when closing the modal.
67
+
68
+ - Type: `Function`
69
+ - Required: Yes.
@@ -0,0 +1,17 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { Modal } from '@wordpress/components';
5
+ import { __ } from '@wordpress/i18n';
6
+
7
+ export default function PreferencesModal( { closeModal, children } ) {
8
+ return (
9
+ <Modal
10
+ className="preferences-modal"
11
+ title={ __( 'Preferences' ) }
12
+ onRequestClose={ closeModal }
13
+ >
14
+ { children }
15
+ </Modal>
16
+ );
17
+ }
@@ -0,0 +1,21 @@
1
+ .preferences-modal {
2
+ // To keep modal dimensions consistent as subsections are navigated, width
3
+ // and height are used instead of max-(width/height).
4
+ @include break-small() {
5
+ width: calc(100% - #{ $grid-unit-20 * 2 });
6
+ height: calc(100% - #{ $header-height * 2 });
7
+ }
8
+ @include break-medium() {
9
+ width: $break-medium - $grid-unit-20 * 2;
10
+ }
11
+ @include break-large() {
12
+ height: 70%;
13
+ }
14
+
15
+ // Clears spacing to flush fit the navigator component to the modal edges.
16
+ @media (max-width: #{ ($break-medium - 1) }) {
17
+ .components-modal__content {
18
+ padding: 0;
19
+ }
20
+ }
21
+ }
@@ -0,0 +1,31 @@
1
+ # PreferencesModalSection
2
+
3
+ `PreferencesModalSection` renders a section (as a fieldset) meant to be used with `PreferencesModal`.
4
+
5
+ ## Example
6
+
7
+ See the `PreferencesModal` readme for usage info.
8
+
9
+
10
+ ## Props
11
+
12
+ ### title
13
+
14
+ The title of the section
15
+
16
+ - Type: `String`
17
+ - Required: Yes.
18
+
19
+ ### description
20
+
21
+ The description for the section.
22
+
23
+ - Type: `String`
24
+ - Required: No.
25
+
26
+ ### children
27
+
28
+ Components to be rendered as content.
29
+
30
+ - Type: `Element`
31
+ - Required: Yes.
@@ -0,0 +1,15 @@
1
+ const Section = ( { description, title, children } ) => (
2
+ <fieldset className="preferences-modal__section">
3
+ <legend className="preferences-modal__section-legend">
4
+ <h2 className="preferences-modal__section-title">{ title }</h2>
5
+ { description && (
6
+ <p className="preferences-modal__section-description">
7
+ { description }
8
+ </p>
9
+ ) }
10
+ </legend>
11
+ <div className="preferences-modal__section-content">{ children }</div>
12
+ </fieldset>
13
+ );
14
+
15
+ export default Section;
@@ -0,0 +1,28 @@
1
+ .preferences-modal__section {
2
+ margin: 0 0 2.5rem 0;
3
+
4
+ &:last-child {
5
+ margin: 0;
6
+ }
7
+ }
8
+
9
+ .preferences-modal__section-legend {
10
+ margin-bottom: $grid-unit-10;
11
+ }
12
+
13
+ .preferences-modal__section-title {
14
+ font-size: 0.9rem;
15
+ font-weight: 600;
16
+ margin-top: 0;
17
+ }
18
+
19
+ .preferences-modal__section-description {
20
+ margin: -$grid-unit-10 0 $grid-unit-10 0;
21
+ font-size: $helptext-font-size;
22
+ font-style: normal;
23
+ color: $gray-700;
24
+ }
25
+
26
+ .preferences-modal__section:has(.preferences-modal__section-content:empty) {
27
+ display: none;
28
+ }
@@ -0,0 +1,14 @@
1
+ # PreferencesModalTabs
2
+
3
+ `PreferencesModalTabs` creates a tabbed interface meant to be used inside a `PreferencesModal`. Markup differs between small and large viewports; on small the tabs are closed by default.
4
+
5
+ ## Example
6
+
7
+ See the `PreferencesModal` readme for usage info.
8
+ ## Props
9
+ ### sections
10
+
11
+ Sections to populate the modal with. Takes an array of objects, where each should include `name`, `tablabel` and `content`.
12
+
13
+ - Type: `Array`
14
+ - Required: Yes.
@@ -0,0 +1,178 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { useViewportMatch } from '@wordpress/compose';
5
+ import {
6
+ __experimentalNavigatorProvider as NavigatorProvider,
7
+ __experimentalNavigatorScreen as NavigatorScreen,
8
+ __experimentalNavigatorButton as NavigatorButton,
9
+ __experimentalNavigatorBackButton as NavigatorBackButton,
10
+ __experimentalItemGroup as ItemGroup,
11
+ __experimentalItem as Item,
12
+ __experimentalHStack as HStack,
13
+ __experimentalText as Text,
14
+ __experimentalTruncate as Truncate,
15
+ FlexItem,
16
+ Card,
17
+ CardHeader,
18
+ CardBody,
19
+ privateApis as componentsPrivateApis,
20
+ } from '@wordpress/components';
21
+ import { useMemo, useState } from '@wordpress/element';
22
+ import { chevronLeft, chevronRight, Icon } from '@wordpress/icons';
23
+ import { isRTL, __ } from '@wordpress/i18n';
24
+
25
+ /**
26
+ * Internal dependencies
27
+ */
28
+ import { unlock } from '../../lock-unlock';
29
+
30
+ const { Tabs } = unlock( componentsPrivateApis );
31
+
32
+ const PREFERENCES_MENU = 'preferences-menu';
33
+
34
+ export default function PreferencesModalTabs( { sections } ) {
35
+ const isLargeViewport = useViewportMatch( 'medium' );
36
+
37
+ // This is also used to sync the two different rendered components
38
+ // between small and large viewports.
39
+ const [ activeMenu, setActiveMenu ] = useState( PREFERENCES_MENU );
40
+ /**
41
+ * Create helper objects from `sections` for easier data handling.
42
+ * `tabs` is used for creating the `Tabs` and `sectionsContentMap`
43
+ * is used for easier access to active tab's content.
44
+ */
45
+ const { tabs, sectionsContentMap } = useMemo( () => {
46
+ let mappedTabs = {
47
+ tabs: [],
48
+ sectionsContentMap: {},
49
+ };
50
+ if ( sections.length ) {
51
+ mappedTabs = sections.reduce(
52
+ ( accumulator, { name, tabLabel: title, content } ) => {
53
+ accumulator.tabs.push( { name, title } );
54
+ accumulator.sectionsContentMap[ name ] = content;
55
+ return accumulator;
56
+ },
57
+ { tabs: [], sectionsContentMap: {} }
58
+ );
59
+ }
60
+ return mappedTabs;
61
+ }, [ sections ] );
62
+
63
+ let modalContent;
64
+ // We render different components based on the viewport size.
65
+ if ( isLargeViewport ) {
66
+ modalContent = (
67
+ <div className="preferences__tabs">
68
+ <Tabs
69
+ initialTabId={
70
+ activeMenu !== PREFERENCES_MENU ? activeMenu : undefined
71
+ }
72
+ onSelect={ setActiveMenu }
73
+ orientation="vertical"
74
+ >
75
+ <Tabs.TabList className="preferences__tabs-tablist">
76
+ { tabs.map( ( tab ) => (
77
+ <Tabs.Tab
78
+ tabId={ tab.name }
79
+ key={ tab.name }
80
+ className="preferences__tabs-tab"
81
+ >
82
+ { tab.title }
83
+ </Tabs.Tab>
84
+ ) ) }
85
+ </Tabs.TabList>
86
+ { tabs.map( ( tab ) => (
87
+ <Tabs.TabPanel
88
+ tabId={ tab.name }
89
+ key={ tab.name }
90
+ className="preferences__tabs-tabpanel"
91
+ focusable={ false }
92
+ >
93
+ { sectionsContentMap[ tab.name ] || null }
94
+ </Tabs.TabPanel>
95
+ ) ) }
96
+ </Tabs>
97
+ </div>
98
+ );
99
+ } else {
100
+ modalContent = (
101
+ <NavigatorProvider
102
+ initialPath="/"
103
+ className="preferences__provider"
104
+ >
105
+ <NavigatorScreen path="/">
106
+ <Card isBorderless size="small">
107
+ <CardBody>
108
+ <ItemGroup>
109
+ { tabs.map( ( tab ) => {
110
+ return (
111
+ <NavigatorButton
112
+ key={ tab.name }
113
+ path={ tab.name }
114
+ as={ Item }
115
+ isAction
116
+ >
117
+ <HStack justify="space-between">
118
+ <FlexItem>
119
+ <Truncate>
120
+ { tab.title }
121
+ </Truncate>
122
+ </FlexItem>
123
+ <FlexItem>
124
+ <Icon
125
+ icon={
126
+ isRTL()
127
+ ? chevronLeft
128
+ : chevronRight
129
+ }
130
+ />
131
+ </FlexItem>
132
+ </HStack>
133
+ </NavigatorButton>
134
+ );
135
+ } ) }
136
+ </ItemGroup>
137
+ </CardBody>
138
+ </Card>
139
+ </NavigatorScreen>
140
+ { sections.length &&
141
+ sections.map( ( section ) => {
142
+ return (
143
+ <NavigatorScreen
144
+ key={ `${ section.name }-menu` }
145
+ path={ section.name }
146
+ >
147
+ <Card isBorderless size="large">
148
+ <CardHeader
149
+ isBorderless={ false }
150
+ justify="left"
151
+ size="small"
152
+ gap="6"
153
+ >
154
+ <NavigatorBackButton
155
+ icon={
156
+ isRTL()
157
+ ? chevronRight
158
+ : chevronLeft
159
+ }
160
+ aria-label={ __(
161
+ 'Navigate to the previous view'
162
+ ) }
163
+ />
164
+ <Text size="16">
165
+ { section.tabLabel }
166
+ </Text>
167
+ </CardHeader>
168
+ <CardBody>{ section.content }</CardBody>
169
+ </Card>
170
+ </NavigatorScreen>
171
+ );
172
+ } ) }
173
+ </NavigatorProvider>
174
+ );
175
+ }
176
+
177
+ return modalContent;
178
+ }
@@ -0,0 +1,48 @@
1
+ $vertical-tabs-width: 160px;
2
+
3
+ .preferences__tabs-tablist {
4
+ position: absolute;
5
+ top: $header-height + $grid-unit-30;
6
+ // Aligns button text instead of button box.
7
+ left: $grid-unit-20;
8
+ width: $vertical-tabs-width;
9
+
10
+ }
11
+
12
+ .preferences__tabs-tab {
13
+ border-radius: $radius-block-ui;
14
+ font-weight: 400;
15
+
16
+ &[aria-selected="true"] {
17
+ background: $gray-100;
18
+ box-shadow: none;
19
+ font-weight: 500;
20
+ }
21
+
22
+ &[aria-selected="true"]::after {
23
+ content: none;
24
+ }
25
+
26
+ &[role="tab"]:focus:not(:disabled) {
27
+ box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color);
28
+ // Windows high contrast mode.
29
+ outline: 2px solid transparent;
30
+ }
31
+
32
+ &:focus-visible::before {
33
+ content: none;
34
+ }
35
+ }
36
+
37
+ .preferences__tabs-tabpanel {
38
+ padding-left: $grid-unit-30;
39
+ margin-left: $vertical-tabs-width;
40
+ }
41
+
42
+ @media (max-width: #{ ($break-medium - 1) }) {
43
+ // Keep the navigator component from overflowing the modal content area
44
+ // to ensure that sticky position elements stick where intended.
45
+ .preferences__provider {
46
+ height: 100%;
47
+ }
48
+ }
package/src/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './components';
2
2
  export { store } from './store';
3
+ export * from './private-apis';
@@ -0,0 +1,9 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';
5
+ export const { lock, unlock } =
6
+ __dangerousOptInToUnstableAPIsOnlyForCoreModules(
7
+ 'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.',
8
+ '@wordpress/preferences'
9
+ );
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import PreferenceBaseOption from './components/preference-base-option';
5
+ import PreferenceToggleControl from './components/preference-toggle-control';
6
+ import PreferencesModal from './components/preferences-modal';
7
+ import PreferencesModalSection from './components/preferences-modal-section';
8
+ import PreferencesModalTabs from './components/preferences-modal-tabs';
9
+ import { lock } from './lock-unlock';
10
+
11
+ export const privateApis = {};
12
+ lock( privateApis, {
13
+ PreferenceBaseOption,
14
+ PreferenceToggleControl,
15
+ PreferencesModal,
16
+ PreferencesModalSection,
17
+ PreferencesModalTabs,
18
+ } );
@@ -12,7 +12,7 @@ import * as selectors from './selectors';
12
12
  import { STORE_NAME } from './constants';
13
13
 
14
14
  /**
15
- * Store definition for the interface namespace.
15
+ * Store definition for the preferences namespace.
16
16
  *
17
17
  * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
18
18
  *
@@ -1,3 +1,43 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import deprecated from '@wordpress/deprecated';
5
+
6
+ const withDeprecatedKeys = ( originalGet ) => ( state, scope, name ) => {
7
+ const settingsToMoveToCore = [
8
+ 'allowRightClickOverrides',
9
+ 'distractionFree',
10
+ 'editorMode',
11
+ 'fixedToolbar',
12
+ 'focusMode',
13
+ 'hiddenBlockTypes',
14
+ 'inactivePanels',
15
+ 'keepCaretInsideBlock',
16
+ 'mostUsedBlocks',
17
+ 'openPanels',
18
+ 'showBlockBreadcrumbs',
19
+ 'showIconLabels',
20
+ 'showListViewByDefault',
21
+ ];
22
+
23
+ if (
24
+ settingsToMoveToCore.includes( name ) &&
25
+ [ 'core/edit-post', 'core/edit-site' ].includes( scope )
26
+ ) {
27
+ deprecated(
28
+ `wp.data.select( 'core/preferences' ).get( '${ scope }', '${ name }' )`,
29
+ {
30
+ since: '6.5',
31
+ alternative: `wp.data.select( 'core/preferences' ).get( 'core', '${ name }' )`,
32
+ }
33
+ );
34
+
35
+ return originalGet( state, 'core', name );
36
+ }
37
+
38
+ return originalGet( state, scope, name );
39
+ };
40
+
1
41
  /**
2
42
  * Returns a boolean indicating whether a prefer is active for a particular
3
43
  * scope.
@@ -8,7 +48,7 @@
8
48
  *
9
49
  * @return {*} Is the feature enabled?
10
50
  */
11
- export function get( state, scope, name ) {
51
+ export const get = withDeprecatedKeys( ( state, scope, name ) => {
12
52
  const value = state.preferences[ scope ]?.[ name ];
13
53
  return value !== undefined ? value : state.defaults[ scope ]?.[ name ];
14
- }
54
+ } );
package/src/style.scss ADDED
@@ -0,0 +1,4 @@
1
+ @import "./components/preference-base-option/style.scss";
2
+ @import "./components/preferences-modal/style.scss";
3
+ @import "./components/preferences-modal-tabs/style.scss";
4
+ @import "./components/preferences-modal-section/style.scss";