@wordpress/preferences 3.26.0 → 3.28.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 (72) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/build/components/preference-base-option/index.js +31 -0
  3. package/build/components/preference-base-option/index.js.map +1 -0
  4. package/build/components/preference-toggle-control/index.js +42 -0
  5. package/build/components/preference-toggle-control/index.js.map +1 -0
  6. package/build/components/preference-toggle-menu-item/index.js +4 -1
  7. package/build/components/preference-toggle-menu-item/index.js.map +1 -1
  8. package/build/components/preferences-modal/index.js +24 -0
  9. package/build/components/preferences-modal/index.js.map +1 -0
  10. package/build/components/preferences-modal-section/index.js +24 -0
  11. package/build/components/preferences-modal-section/index.js.map +1 -0
  12. package/build/components/preferences-modal-tabs/index.js +129 -0
  13. package/build/components/preferences-modal-tabs/index.js.map +1 -0
  14. package/build/index.js +12 -0
  15. package/build/index.js.map +1 -1
  16. package/build/lock-unlock.js +18 -0
  17. package/build/lock-unlock.js.map +1 -0
  18. package/build/private-apis.js +26 -0
  19. package/build/private-apis.js.map +1 -0
  20. package/build/store/constants.js +1 -2
  21. package/build/store/constants.js.map +1 -1
  22. package/build/store/index.js +4 -5
  23. package/build/store/index.js.map +1 -1
  24. package/build/store/reducer.js +2 -4
  25. package/build/store/reducer.js.map +1 -1
  26. package/build/store/selectors.js +21 -3
  27. package/build/store/selectors.js.map +1 -1
  28. package/build-module/components/preference-base-option/index.js +24 -0
  29. package/build-module/components/preference-base-option/index.js.map +1 -0
  30. package/build-module/components/preference-toggle-control/index.js +34 -0
  31. package/build-module/components/preference-toggle-control/index.js.map +1 -0
  32. package/build-module/components/preference-toggle-menu-item/index.js +4 -1
  33. package/build-module/components/preference-toggle-menu-item/index.js.map +1 -1
  34. package/build-module/components/preferences-modal/index.js +17 -0
  35. package/build-module/components/preferences-modal/index.js.map +1 -0
  36. package/build-module/components/preferences-modal-section/index.js +18 -0
  37. package/build-module/components/preferences-modal-section/index.js.map +1 -0
  38. package/build-module/components/preferences-modal-tabs/index.js +122 -0
  39. package/build-module/components/preferences-modal-tabs/index.js.map +1 -0
  40. package/build-module/index.js +1 -0
  41. package/build-module/index.js.map +1 -1
  42. package/build-module/lock-unlock.js +9 -0
  43. package/build-module/lock-unlock.js.map +1 -0
  44. package/build-module/private-apis.js +18 -0
  45. package/build-module/private-apis.js.map +1 -0
  46. package/build-module/store/index.js +1 -1
  47. package/build-module/store/index.js.map +1 -1
  48. package/build-module/store/selectors.js +18 -2
  49. package/build-module/store/selectors.js.map +1 -1
  50. package/build-style/style-rtl.css +199 -0
  51. package/build-style/style.css +199 -0
  52. package/package.json +11 -8
  53. package/src/components/preference-base-option/README.md +40 -0
  54. package/src/components/preference-base-option/index.js +21 -0
  55. package/src/components/preference-base-option/style.scss +10 -0
  56. package/src/components/preference-toggle-control/index.js +38 -0
  57. package/src/components/preference-toggle-menu-item/index.js +4 -1
  58. package/src/components/preferences-modal/README.md +69 -0
  59. package/src/components/preferences-modal/index.js +17 -0
  60. package/src/components/preferences-modal/style.scss +21 -0
  61. package/src/components/preferences-modal-section/README.md +31 -0
  62. package/src/components/preferences-modal-section/index.js +15 -0
  63. package/src/components/preferences-modal-section/style.scss +28 -0
  64. package/src/components/preferences-modal-tabs/README.md +14 -0
  65. package/src/components/preferences-modal-tabs/index.js +178 -0
  66. package/src/components/preferences-modal-tabs/style.scss +48 -0
  67. package/src/index.js +1 -0
  68. package/src/lock-unlock.js +9 -0
  69. package/src/private-apis.js +18 -0
  70. package/src/store/index.js +1 -1
  71. package/src/store/selectors.js +42 -2
  72. package/src/style.scss +4 -0
@@ -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";