@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.
- package/CHANGELOG.md +4 -0
- package/build/components/preference-base-option/index.js +31 -0
- package/build/components/preference-base-option/index.js.map +1 -0
- package/build/components/preference-toggle-control/index.js +42 -0
- package/build/components/preference-toggle-control/index.js.map +1 -0
- package/build/components/preference-toggle-menu-item/index.js +4 -1
- package/build/components/preference-toggle-menu-item/index.js.map +1 -1
- package/build/components/preferences-modal/index.js +24 -0
- package/build/components/preferences-modal/index.js.map +1 -0
- package/build/components/preferences-modal-section/index.js +24 -0
- package/build/components/preferences-modal-section/index.js.map +1 -0
- package/build/components/preferences-modal-tabs/index.js +129 -0
- package/build/components/preferences-modal-tabs/index.js.map +1 -0
- package/build/index.js +12 -0
- package/build/index.js.map +1 -1
- package/build/lock-unlock.js +18 -0
- package/build/lock-unlock.js.map +1 -0
- package/build/private-apis.js +26 -0
- package/build/private-apis.js.map +1 -0
- package/build/store/constants.js +1 -2
- package/build/store/constants.js.map +1 -1
- package/build/store/index.js +4 -5
- package/build/store/index.js.map +1 -1
- package/build/store/reducer.js +2 -4
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +21 -3
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/preference-base-option/index.js +24 -0
- package/build-module/components/preference-base-option/index.js.map +1 -0
- package/build-module/components/preference-toggle-control/index.js +34 -0
- package/build-module/components/preference-toggle-control/index.js.map +1 -0
- package/build-module/components/preference-toggle-menu-item/index.js +4 -1
- package/build-module/components/preference-toggle-menu-item/index.js.map +1 -1
- package/build-module/components/preferences-modal/index.js +17 -0
- package/build-module/components/preferences-modal/index.js.map +1 -0
- package/build-module/components/preferences-modal-section/index.js +18 -0
- package/build-module/components/preferences-modal-section/index.js.map +1 -0
- package/build-module/components/preferences-modal-tabs/index.js +122 -0
- package/build-module/components/preferences-modal-tabs/index.js.map +1 -0
- package/build-module/index.js +1 -0
- package/build-module/index.js.map +1 -1
- package/build-module/lock-unlock.js +9 -0
- package/build-module/lock-unlock.js.map +1 -0
- package/build-module/private-apis.js +18 -0
- package/build-module/private-apis.js.map +1 -0
- package/build-module/store/index.js +1 -1
- package/build-module/store/index.js.map +1 -1
- package/build-module/store/selectors.js +18 -2
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +199 -0
- package/build-style/style.css +199 -0
- package/package.json +11 -8
- package/src/components/preference-base-option/README.md +40 -0
- package/src/components/preference-base-option/index.js +21 -0
- package/src/components/preference-base-option/style.scss +10 -0
- package/src/components/preference-toggle-control/index.js +38 -0
- package/src/components/preference-toggle-menu-item/index.js +4 -1
- package/src/components/preferences-modal/README.md +69 -0
- package/src/components/preferences-modal/index.js +17 -0
- package/src/components/preferences-modal/style.scss +21 -0
- package/src/components/preferences-modal-section/README.md +31 -0
- package/src/components/preferences-modal-section/index.js +15 -0
- package/src/components/preferences-modal-section/style.scss +28 -0
- package/src/components/preferences-modal-tabs/README.md +14 -0
- package/src/components/preferences-modal-tabs/index.js +178 -0
- package/src/components/preferences-modal-tabs/style.scss +48 -0
- package/src/index.js +1 -0
- package/src/lock-unlock.js +9 -0
- package/src/private-apis.js +18 -0
- package/src/store/index.js +1 -1
- package/src/store/selectors.js +42 -2
- 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
|
@@ -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
|
+
} );
|
package/src/store/index.js
CHANGED
|
@@ -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
|
|
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
|
*
|
package/src/store/selectors.js
CHANGED
|
@@ -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
|
|
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