@wordpress/block-library 9.30.0 → 9.30.1-next.6f42e1382.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/build/accordion-content/edit.js +8 -8
- package/build/accordion-content/edit.js.map +1 -1
- package/build/accordion-content/index.js +2 -1
- package/build/accordion-content/index.js.map +1 -1
- package/build/accordion-panel/index.js +2 -1
- package/build/accordion-panel/index.js.map +1 -1
- package/build/buttons/index.js +2 -1
- package/build/buttons/index.js.map +1 -1
- package/build/categories/edit.js +3 -1
- package/build/categories/edit.js.map +1 -1
- package/build/index.js +4 -0
- package/build/index.js.map +1 -1
- package/build/navigation/constants.js +5 -1
- package/build/navigation/constants.js.map +1 -1
- package/build/navigation/edit/index.js +45 -1
- package/build/navigation/edit/index.js.map +1 -1
- package/build/navigation/edit/leaf-more-menu.js +0 -1
- package/build/navigation/edit/leaf-more-menu.js.map +1 -1
- package/build/navigation/edit/menu-inspector-controls.js +40 -5
- package/build/navigation/edit/menu-inspector-controls.js.map +1 -1
- package/build/navigation-link/block-inserter.js +69 -0
- package/build/navigation-link/block-inserter.js.map +1 -0
- package/build/navigation-link/dialog-wrapper.js +80 -0
- package/build/navigation-link/dialog-wrapper.js.map +1 -0
- package/build/navigation-link/link-ui.js +80 -120
- package/build/navigation-link/link-ui.js.map +1 -1
- package/build/navigation-link/page-creator.js +137 -0
- package/build/navigation-link/page-creator.js.map +1 -0
- package/build/search/edit.js +22 -14
- package/build/search/edit.js.map +1 -1
- package/build/social-links/index.js +2 -1
- package/build/social-links/index.js.map +1 -1
- package/build/table-of-contents/edit.js +33 -9
- package/build/table-of-contents/edit.js.map +1 -1
- package/build/table-of-contents/index.js +4 -0
- package/build/table-of-contents/index.js.map +1 -1
- package/build/table-of-contents/list.js +6 -3
- package/build/table-of-contents/list.js.map +1 -1
- package/build/table-of-contents/save.js +6 -3
- package/build/table-of-contents/save.js.map +1 -1
- package/build/term-template/edit.js +318 -0
- package/build/term-template/edit.js.map +1 -0
- package/build/term-template/index.js +109 -0
- package/build/term-template/index.js.map +1 -0
- package/build/term-template/save.js +16 -0
- package/build/term-template/save.js.map +1 -0
- package/build/term-template/variations.js +83 -0
- package/build/term-template/variations.js.map +1 -0
- package/build/terms-query/edit.js +20 -0
- package/build/terms-query/edit.js.map +1 -0
- package/build/terms-query/index.js +83 -0
- package/build/terms-query/index.js.map +1 -0
- package/build/terms-query/inspector-controls.js +246 -0
- package/build/terms-query/inspector-controls.js.map +1 -0
- package/build/terms-query/save.js +24 -0
- package/build/terms-query/save.js.map +1 -0
- package/build/terms-query/terms-query-content.js +71 -0
- package/build/terms-query/terms-query-content.js.map +1 -0
- package/build-module/accordion-content/edit.js +8 -8
- package/build-module/accordion-content/edit.js.map +1 -1
- package/build-module/accordion-content/index.js +2 -1
- package/build-module/accordion-content/index.js.map +1 -1
- package/build-module/accordion-panel/index.js +2 -1
- package/build-module/accordion-panel/index.js.map +1 -1
- package/build-module/buttons/index.js +2 -1
- package/build-module/buttons/index.js.map +1 -1
- package/build-module/categories/edit.js +3 -1
- package/build-module/categories/edit.js.map +1 -1
- package/build-module/index.js +4 -0
- package/build-module/index.js.map +1 -1
- package/build-module/navigation/constants.js +5 -1
- package/build-module/navigation/constants.js.map +1 -1
- package/build-module/navigation/edit/index.js +50 -4
- package/build-module/navigation/edit/index.js.map +1 -1
- package/build-module/navigation/edit/leaf-more-menu.js +0 -1
- package/build-module/navigation/edit/leaf-more-menu.js.map +1 -1
- package/build-module/navigation/edit/menu-inspector-controls.js +40 -5
- package/build-module/navigation/edit/menu-inspector-controls.js.map +1 -1
- package/build-module/navigation-link/block-inserter.js +61 -0
- package/build-module/navigation-link/block-inserter.js.map +1 -0
- package/build-module/navigation-link/dialog-wrapper.js +75 -0
- package/build-module/navigation-link/dialog-wrapper.js.map +1 -0
- package/build-module/navigation-link/link-ui.js +85 -125
- package/build-module/navigation-link/link-ui.js.map +1 -1
- package/build-module/navigation-link/page-creator.js +130 -0
- package/build-module/navigation-link/page-creator.js.map +1 -0
- package/build-module/search/edit.js +22 -14
- package/build-module/search/edit.js.map +1 -1
- package/build-module/social-links/index.js +2 -1
- package/build-module/social-links/index.js.map +1 -1
- package/build-module/table-of-contents/edit.js +35 -11
- package/build-module/table-of-contents/edit.js.map +1 -1
- package/build-module/table-of-contents/index.js +4 -0
- package/build-module/table-of-contents/index.js.map +1 -1
- package/build-module/table-of-contents/list.js +6 -3
- package/build-module/table-of-contents/list.js.map +1 -1
- package/build-module/table-of-contents/save.js +6 -3
- package/build-module/table-of-contents/save.js.map +1 -1
- package/build-module/term-template/edit.js +310 -0
- package/build-module/term-template/edit.js.map +1 -0
- package/build-module/term-template/index.js +102 -0
- package/build-module/term-template/index.js.map +1 -0
- package/build-module/term-template/save.js +9 -0
- package/build-module/term-template/save.js.map +1 -0
- package/build-module/term-template/variations.js +76 -0
- package/build-module/term-template/variations.js.map +1 -0
- package/build-module/terms-query/edit.js +12 -0
- package/build-module/terms-query/edit.js.map +1 -0
- package/build-module/terms-query/index.js +76 -0
- package/build-module/terms-query/index.js.map +1 -0
- package/build-module/terms-query/inspector-controls.js +239 -0
- package/build-module/terms-query/inspector-controls.js.map +1 -0
- package/build-module/terms-query/save.js +17 -0
- package/build-module/terms-query/save.js.map +1 -0
- package/build-module/terms-query/terms-query-content.js +63 -0
- package/build-module/terms-query/terms-query-content.js.map +1 -0
- package/build-style/accordion/style-rtl.css +5 -6
- package/build-style/accordion/style.css +5 -6
- package/build-style/editor-rtl.css +38 -0
- package/build-style/editor.css +38 -0
- package/build-style/form-input/style-rtl.css +4 -3
- package/build-style/form-input/style.css +4 -3
- package/build-style/navigation-link/editor-rtl.css +14 -0
- package/build-style/navigation-link/editor.css +14 -0
- package/build-style/navigation-link/style-rtl.css +1 -1
- package/build-style/navigation-link/style.css +1 -1
- package/build-style/post-comments-form/style-rtl.css +8 -5
- package/build-style/post-comments-form/style.css +8 -5
- package/build-style/search/style-rtl.css +11 -12
- package/build-style/search/style.css +11 -12
- package/build-style/style-rtl.css +45 -27
- package/build-style/style.css +45 -27
- package/build-style/term-template/editor-rtl.css +160 -0
- package/build-style/term-template/editor.css +160 -0
- package/build-style/term-template/style-rtl.css +146 -0
- package/build-style/term-template/style.css +146 -0
- package/build-style/terms-query/style-rtl.css +140 -0
- package/build-style/terms-query/style.css +140 -0
- package/build-types/table-of-contents/list.d.ts +2 -1
- package/build-types/table-of-contents/list.d.ts.map +1 -1
- package/package.json +35 -35
- package/src/accordion/style.scss +6 -6
- package/src/accordion-content/block.json +2 -1
- package/src/accordion-content/edit.js +21 -27
- package/src/accordion-panel/block.json +2 -1
- package/src/buttons/block.json +2 -1
- package/src/categories/edit.js +2 -1
- package/src/cover/test/edit.js +1 -5
- package/src/editor.scss +1 -0
- package/src/form-input/style.scss +3 -2
- package/src/index.js +4 -0
- package/src/navigation/constants.js +4 -0
- package/src/navigation/edit/index.js +50 -1
- package/src/navigation/edit/leaf-more-menu.js +0 -1
- package/src/navigation/edit/menu-inspector-controls.js +40 -5
- package/src/navigation-link/block-inserter.js +65 -0
- package/src/navigation-link/dialog-wrapper.js +74 -0
- package/src/navigation-link/editor.scss +17 -0
- package/src/navigation-link/link-ui.js +108 -164
- package/src/navigation-link/page-creator.js +157 -0
- package/src/navigation-link/style.scss +1 -1
- package/src/post-comments-form/style.scss +11 -11
- package/src/post-date/index.php +18 -13
- package/src/search/edit.js +44 -13
- package/src/search/index.php +16 -2
- package/src/search/style.scss +15 -16
- package/src/social-links/block.json +2 -1
- package/src/style.scss +2 -0
- package/src/table-of-contents/block.json +4 -0
- package/src/table-of-contents/edit.js +58 -21
- package/src/table-of-contents/list.tsx +7 -2
- package/src/table-of-contents/save.js +7 -3
- package/src/term-template/block.json +73 -0
- package/src/term-template/edit.js +391 -0
- package/src/term-template/editor.scss +26 -0
- package/src/term-template/index.js +26 -0
- package/src/term-template/index.php +224 -0
- package/src/term-template/save.js +8 -0
- package/src/term-template/style.scss +12 -0
- package/src/term-template/variations.js +87 -0
- package/src/terms-query/block.json +49 -0
- package/src/terms-query/edit.js +10 -0
- package/src/terms-query/index.js +24 -0
- package/src/terms-query/index.php +44 -0
- package/src/terms-query/inspector-controls.js +233 -0
- package/src/terms-query/save.js +10 -0
- package/src/terms-query/style.scss +6 -0
- package/src/terms-query/terms-query-content.js +74 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -8,38 +8,24 @@ import {
|
|
|
8
8
|
VisuallyHidden,
|
|
9
9
|
__experimentalVStack as VStack,
|
|
10
10
|
} from '@wordpress/components';
|
|
11
|
-
import { __
|
|
11
|
+
import { __ } from '@wordpress/i18n';
|
|
12
|
+
import { LinkControl, useBlockEditingMode } from '@wordpress/block-editor';
|
|
12
13
|
import {
|
|
13
|
-
LinkControl,
|
|
14
|
-
store as blockEditorStore,
|
|
15
|
-
privateApis as blockEditorPrivateApis,
|
|
16
|
-
useBlockEditingMode,
|
|
17
|
-
} from '@wordpress/block-editor';
|
|
18
|
-
import {
|
|
19
|
-
createInterpolateElement,
|
|
20
14
|
useMemo,
|
|
21
15
|
useState,
|
|
22
16
|
useRef,
|
|
23
17
|
useEffect,
|
|
24
18
|
forwardRef,
|
|
25
19
|
} from '@wordpress/element';
|
|
26
|
-
import {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
} from '@wordpress/core-data';
|
|
30
|
-
import { decodeEntities } from '@wordpress/html-entities';
|
|
31
|
-
import { useSelect, useDispatch } from '@wordpress/data';
|
|
32
|
-
import { chevronLeftSmall, chevronRightSmall, plus } from '@wordpress/icons';
|
|
33
|
-
import { useInstanceId, useFocusOnMount } from '@wordpress/compose';
|
|
20
|
+
import { useResourcePermissions } from '@wordpress/core-data';
|
|
21
|
+
import { plus } from '@wordpress/icons';
|
|
22
|
+
import { useInstanceId } from '@wordpress/compose';
|
|
34
23
|
|
|
35
24
|
/**
|
|
36
25
|
* Internal dependencies
|
|
37
26
|
*/
|
|
38
|
-
import {
|
|
39
|
-
|
|
40
|
-
const { PrivateQuickInserter: QuickInserter } = unlock(
|
|
41
|
-
blockEditorPrivateApis
|
|
42
|
-
);
|
|
27
|
+
import { LinkUIPageCreator } from './page-creator';
|
|
28
|
+
import LinkUIBlockInserter from './block-inserter';
|
|
43
29
|
|
|
44
30
|
/**
|
|
45
31
|
* Given the Link block's type attribute, return the query params to give to
|
|
@@ -79,114 +65,19 @@ export function getSuggestionsQuery( type, kind ) {
|
|
|
79
65
|
}
|
|
80
66
|
}
|
|
81
67
|
|
|
82
|
-
function LinkUIBlockInserter( { clientId, onBack } ) {
|
|
83
|
-
const { rootBlockClientId } = useSelect(
|
|
84
|
-
( select ) => {
|
|
85
|
-
const { getBlockRootClientId } = select( blockEditorStore );
|
|
86
|
-
|
|
87
|
-
return {
|
|
88
|
-
rootBlockClientId: getBlockRootClientId( clientId ),
|
|
89
|
-
};
|
|
90
|
-
},
|
|
91
|
-
[ clientId ]
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
const focusOnMountRef = useFocusOnMount( 'firstElement' );
|
|
95
|
-
|
|
96
|
-
const dialogTitleId = useInstanceId(
|
|
97
|
-
LinkControl,
|
|
98
|
-
`link-ui-block-inserter__title`
|
|
99
|
-
);
|
|
100
|
-
const dialogDescriptionId = useInstanceId(
|
|
101
|
-
LinkControl,
|
|
102
|
-
`link-ui-block-inserter__description`
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
if ( ! clientId ) {
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return (
|
|
110
|
-
<div
|
|
111
|
-
className="link-ui-block-inserter"
|
|
112
|
-
role="dialog"
|
|
113
|
-
aria-labelledby={ dialogTitleId }
|
|
114
|
-
aria-describedby={ dialogDescriptionId }
|
|
115
|
-
ref={ focusOnMountRef }
|
|
116
|
-
>
|
|
117
|
-
<VisuallyHidden>
|
|
118
|
-
<h2 id={ dialogTitleId }>{ __( 'Add block' ) }</h2>
|
|
119
|
-
|
|
120
|
-
<p id={ dialogDescriptionId }>
|
|
121
|
-
{ __( 'Choose a block to add to your Navigation.' ) }
|
|
122
|
-
</p>
|
|
123
|
-
</VisuallyHidden>
|
|
124
|
-
|
|
125
|
-
<Button
|
|
126
|
-
className="link-ui-block-inserter__back"
|
|
127
|
-
icon={ isRTL() ? chevronRightSmall : chevronLeftSmall }
|
|
128
|
-
onClick={ ( e ) => {
|
|
129
|
-
e.preventDefault();
|
|
130
|
-
onBack();
|
|
131
|
-
} }
|
|
132
|
-
size="small"
|
|
133
|
-
>
|
|
134
|
-
{ __( 'Back' ) }
|
|
135
|
-
</Button>
|
|
136
|
-
|
|
137
|
-
<QuickInserter
|
|
138
|
-
rootClientId={ rootBlockClientId }
|
|
139
|
-
clientId={ clientId }
|
|
140
|
-
isAppender={ false }
|
|
141
|
-
prioritizePatterns={ false }
|
|
142
|
-
selectBlockOnInsert
|
|
143
|
-
hasSearch={ false }
|
|
144
|
-
/>
|
|
145
|
-
</div>
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
68
|
function UnforwardedLinkUI( props, ref ) {
|
|
150
69
|
const { label, url, opensInNewTab, type, kind } = props.link;
|
|
151
70
|
const postType = type || 'page';
|
|
152
71
|
|
|
153
72
|
const [ addingBlock, setAddingBlock ] = useState( false );
|
|
73
|
+
const [ addingPage, setAddingPage ] = useState( false );
|
|
154
74
|
const [ focusAddBlockButton, setFocusAddBlockButton ] = useState( false );
|
|
155
|
-
const
|
|
75
|
+
const [ focusAddPageButton, setFocusAddPageButton ] = useState( false );
|
|
156
76
|
const permissions = useResourcePermissions( {
|
|
157
77
|
kind: 'postType',
|
|
158
78
|
name: postType,
|
|
159
79
|
} );
|
|
160
80
|
|
|
161
|
-
// Check if we're in contentOnly mode
|
|
162
|
-
const blockEditingMode = useBlockEditingMode();
|
|
163
|
-
const isDefaultBlockEditingMode = blockEditingMode === 'default';
|
|
164
|
-
|
|
165
|
-
async function handleCreate( pageTitle ) {
|
|
166
|
-
const page = await saveEntityRecord( 'postType', postType, {
|
|
167
|
-
title: pageTitle,
|
|
168
|
-
status: 'draft',
|
|
169
|
-
} );
|
|
170
|
-
|
|
171
|
-
return {
|
|
172
|
-
id: page.id,
|
|
173
|
-
type: postType,
|
|
174
|
-
// Make `title` property consistent with that in `fetchLinkSuggestions` where the `rendered` title (containing HTML entities)
|
|
175
|
-
// is also being decoded. By being consistent in both locations we avoid having to branch in the rendering output code.
|
|
176
|
-
// Ideally in the future we will update both APIs to utilise the "raw" form of the title which is better suited to edit contexts.
|
|
177
|
-
// e.g.
|
|
178
|
-
// - title.raw = "Yes & No"
|
|
179
|
-
// - title.rendered = "Yes & No"
|
|
180
|
-
// - decodeEntities( title.rendered ) = "Yes & No"
|
|
181
|
-
// See:
|
|
182
|
-
// - https://github.com/WordPress/gutenberg/pull/41063
|
|
183
|
-
// - https://github.com/WordPress/gutenberg/blob/a1e1fdc0e6278457e9f4fc0b31ac6d2095f5450b/packages/core-data/src/fetch/__experimental-fetch-link-suggestions.js#L212-L218
|
|
184
|
-
title: decodeEntities( page.title.rendered ),
|
|
185
|
-
url: page.link,
|
|
186
|
-
kind: 'post-type',
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
|
|
190
81
|
// Memoize link value to avoid overriding the LinkControl's internal state.
|
|
191
82
|
// This is a temporary fix. See https://github.com/WordPress/gutenberg/issues/50976#issuecomment-1568226407.
|
|
192
83
|
const link = useMemo(
|
|
@@ -198,15 +89,24 @@ function UnforwardedLinkUI( props, ref ) {
|
|
|
198
89
|
[ label, opensInNewTab, url ]
|
|
199
90
|
);
|
|
200
91
|
|
|
92
|
+
const handlePageCreated = ( pageLink ) => {
|
|
93
|
+
// Set the new page as the current link
|
|
94
|
+
props.onChange( pageLink );
|
|
95
|
+
// Return to main Link UI
|
|
96
|
+
setAddingPage( false );
|
|
97
|
+
};
|
|
98
|
+
|
|
201
99
|
const dialogTitleId = useInstanceId(
|
|
202
100
|
LinkUI,
|
|
203
|
-
|
|
101
|
+
'link-ui-link-control__title'
|
|
204
102
|
);
|
|
205
103
|
const dialogDescriptionId = useInstanceId(
|
|
206
104
|
LinkUI,
|
|
207
|
-
|
|
105
|
+
'link-ui-link-control__description'
|
|
208
106
|
);
|
|
209
107
|
|
|
108
|
+
const blockEditingMode = useBlockEditingMode();
|
|
109
|
+
|
|
210
110
|
return (
|
|
211
111
|
<Popover
|
|
212
112
|
ref={ ref }
|
|
@@ -215,7 +115,7 @@ function UnforwardedLinkUI( props, ref ) {
|
|
|
215
115
|
anchor={ props.anchor }
|
|
216
116
|
shift
|
|
217
117
|
>
|
|
218
|
-
{ ! addingBlock && (
|
|
118
|
+
{ ! addingBlock && ! addingPage && (
|
|
219
119
|
<div
|
|
220
120
|
role="dialog"
|
|
221
121
|
aria-labelledby={ dialogTitleId }
|
|
@@ -235,48 +135,41 @@ function UnforwardedLinkUI( props, ref ) {
|
|
|
235
135
|
hasRichPreviews
|
|
236
136
|
value={ link }
|
|
237
137
|
showInitialSuggestions
|
|
238
|
-
withCreateSuggestion={
|
|
239
|
-
createSuggestion={ handleCreate }
|
|
240
|
-
createSuggestionButtonText={ ( searchTerm ) => {
|
|
241
|
-
let format;
|
|
242
|
-
|
|
243
|
-
if ( type === 'post' ) {
|
|
244
|
-
/* translators: %s: search term. */
|
|
245
|
-
format = __(
|
|
246
|
-
'Create draft post: <mark>%s</mark>'
|
|
247
|
-
);
|
|
248
|
-
} else {
|
|
249
|
-
/* translators: %s: search term. */
|
|
250
|
-
format = __(
|
|
251
|
-
'Create draft page: <mark>%s</mark>'
|
|
252
|
-
);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
return createInterpolateElement(
|
|
256
|
-
sprintf( format, searchTerm ),
|
|
257
|
-
{
|
|
258
|
-
mark: <mark />,
|
|
259
|
-
}
|
|
260
|
-
);
|
|
261
|
-
} }
|
|
138
|
+
withCreateSuggestion={ false }
|
|
262
139
|
noDirectEntry={ !! type }
|
|
263
140
|
noURLSuggestion={ !! type }
|
|
264
141
|
suggestionsQuery={ getSuggestionsQuery( type, kind ) }
|
|
265
142
|
onChange={ props.onChange }
|
|
266
143
|
onRemove={ props.onRemove }
|
|
267
144
|
onCancel={ props.onCancel }
|
|
268
|
-
renderControlBottom={ () =>
|
|
269
|
-
|
|
270
|
-
|
|
145
|
+
renderControlBottom={ () => {
|
|
146
|
+
// Don't show the tools when there is submitted link (preview state).
|
|
147
|
+
if ( link?.url?.length ) {
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return (
|
|
271
152
|
<LinkUITools
|
|
272
153
|
focusAddBlockButton={ focusAddBlockButton }
|
|
154
|
+
focusAddPageButton={ focusAddPageButton }
|
|
273
155
|
setAddingBlock={ () => {
|
|
274
156
|
setAddingBlock( true );
|
|
275
157
|
setFocusAddBlockButton( false );
|
|
276
158
|
} }
|
|
159
|
+
setAddingPage={ () => {
|
|
160
|
+
setAddingPage( true );
|
|
161
|
+
setFocusAddPageButton( false );
|
|
162
|
+
} }
|
|
163
|
+
canAddPage={
|
|
164
|
+
permissions?.canCreate &&
|
|
165
|
+
type === 'page'
|
|
166
|
+
}
|
|
167
|
+
canAddBlock={
|
|
168
|
+
blockEditingMode === 'default'
|
|
169
|
+
}
|
|
277
170
|
/>
|
|
278
|
-
)
|
|
279
|
-
}
|
|
171
|
+
);
|
|
172
|
+
} }
|
|
280
173
|
/>
|
|
281
174
|
</div>
|
|
282
175
|
) }
|
|
@@ -287,7 +180,22 @@ function UnforwardedLinkUI( props, ref ) {
|
|
|
287
180
|
onBack={ () => {
|
|
288
181
|
setAddingBlock( false );
|
|
289
182
|
setFocusAddBlockButton( true );
|
|
183
|
+
setFocusAddPageButton( false );
|
|
184
|
+
} }
|
|
185
|
+
onBlockInsert={ props?.onBlockInsert }
|
|
186
|
+
/>
|
|
187
|
+
) }
|
|
188
|
+
|
|
189
|
+
{ addingPage && (
|
|
190
|
+
<LinkUIPageCreator
|
|
191
|
+
postType={ postType }
|
|
192
|
+
onBack={ () => {
|
|
193
|
+
setAddingPage( false );
|
|
194
|
+
setFocusAddPageButton( true );
|
|
195
|
+
setFocusAddBlockButton( false );
|
|
290
196
|
} }
|
|
197
|
+
onPageCreated={ handlePageCreated }
|
|
198
|
+
initialTitle={ link?.url || '' }
|
|
291
199
|
/>
|
|
292
200
|
) }
|
|
293
201
|
</Popover>
|
|
@@ -296,9 +204,17 @@ function UnforwardedLinkUI( props, ref ) {
|
|
|
296
204
|
|
|
297
205
|
export const LinkUI = forwardRef( UnforwardedLinkUI );
|
|
298
206
|
|
|
299
|
-
const LinkUITools = ( {
|
|
207
|
+
const LinkUITools = ( {
|
|
208
|
+
setAddingBlock,
|
|
209
|
+
setAddingPage,
|
|
210
|
+
focusAddBlockButton,
|
|
211
|
+
focusAddPageButton,
|
|
212
|
+
canAddPage,
|
|
213
|
+
canAddBlock,
|
|
214
|
+
} ) => {
|
|
300
215
|
const blockInserterAriaRole = 'listbox';
|
|
301
216
|
const addBlockButtonRef = useRef();
|
|
217
|
+
const addPageButtonRef = useRef();
|
|
302
218
|
|
|
303
219
|
// Focus the add block button when the popover is opened.
|
|
304
220
|
useEffect( () => {
|
|
@@ -307,20 +223,48 @@ const LinkUITools = ( { setAddingBlock, focusAddBlockButton } ) => {
|
|
|
307
223
|
}
|
|
308
224
|
}, [ focusAddBlockButton ] );
|
|
309
225
|
|
|
226
|
+
// Focus the add page button when the popover is opened.
|
|
227
|
+
useEffect( () => {
|
|
228
|
+
if ( focusAddPageButton ) {
|
|
229
|
+
addPageButtonRef.current?.focus();
|
|
230
|
+
}
|
|
231
|
+
}, [ focusAddPageButton ] );
|
|
232
|
+
|
|
233
|
+
// Don't render anything if neither button should be shown
|
|
234
|
+
if ( ! canAddPage && ! canAddBlock ) {
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
|
|
310
238
|
return (
|
|
311
|
-
<VStack className="link-ui-tools">
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
e
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
239
|
+
<VStack spacing={ 0 } className="link-ui-tools">
|
|
240
|
+
{ canAddPage && (
|
|
241
|
+
<Button
|
|
242
|
+
__next40pxDefaultSize
|
|
243
|
+
ref={ addPageButtonRef }
|
|
244
|
+
icon={ plus }
|
|
245
|
+
onClick={ ( e ) => {
|
|
246
|
+
e.preventDefault();
|
|
247
|
+
setAddingPage( true );
|
|
248
|
+
} }
|
|
249
|
+
aria-haspopup={ blockInserterAriaRole }
|
|
250
|
+
>
|
|
251
|
+
{ __( 'Create page' ) }
|
|
252
|
+
</Button>
|
|
253
|
+
) }
|
|
254
|
+
{ canAddBlock && (
|
|
255
|
+
<Button
|
|
256
|
+
__next40pxDefaultSize
|
|
257
|
+
ref={ addBlockButtonRef }
|
|
258
|
+
icon={ plus }
|
|
259
|
+
onClick={ ( e ) => {
|
|
260
|
+
e.preventDefault();
|
|
261
|
+
setAddingBlock( true );
|
|
262
|
+
} }
|
|
263
|
+
aria-haspopup={ blockInserterAriaRole }
|
|
264
|
+
>
|
|
265
|
+
{ __( 'Add block' ) }
|
|
266
|
+
</Button>
|
|
267
|
+
) }
|
|
324
268
|
</VStack>
|
|
325
269
|
);
|
|
326
270
|
};
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import {
|
|
5
|
+
Button,
|
|
6
|
+
TextControl,
|
|
7
|
+
Notice,
|
|
8
|
+
CheckboxControl,
|
|
9
|
+
__experimentalVStack as VStack,
|
|
10
|
+
__experimentalHStack as HStack,
|
|
11
|
+
} from '@wordpress/components';
|
|
12
|
+
import { __ } from '@wordpress/i18n';
|
|
13
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
14
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
15
|
+
import { decodeEntities } from '@wordpress/html-entities';
|
|
16
|
+
import { useState } from '@wordpress/element';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Internal dependencies
|
|
20
|
+
*/
|
|
21
|
+
import DialogWrapper from './dialog-wrapper';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Component for creating new pages within the Navigation Link UI.
|
|
25
|
+
*
|
|
26
|
+
* @param {Object} props Component props.
|
|
27
|
+
* @param {string} props.postType The post type to create.
|
|
28
|
+
* @param {Function} props.onBack Callback when user wants to go back.
|
|
29
|
+
* @param {Function} props.onPageCreated Callback when page is successfully created.
|
|
30
|
+
* @param {string} [props.initialTitle] Initial title to pre-fill the form.
|
|
31
|
+
*/
|
|
32
|
+
export function LinkUIPageCreator( {
|
|
33
|
+
postType,
|
|
34
|
+
onBack,
|
|
35
|
+
onPageCreated,
|
|
36
|
+
initialTitle = '',
|
|
37
|
+
} ) {
|
|
38
|
+
const [ title, setTitle ] = useState( initialTitle );
|
|
39
|
+
const [ shouldPublish, setShouldPublish ] = useState( false );
|
|
40
|
+
|
|
41
|
+
// Check if the title is valid for submission
|
|
42
|
+
const isTitleValid = title.trim().length > 0;
|
|
43
|
+
|
|
44
|
+
// Get the last created entity record (without ID) to track creation state
|
|
45
|
+
const { lastError, isSaving } = useSelect(
|
|
46
|
+
( select ) => ( {
|
|
47
|
+
lastError: select( coreStore ).getLastEntitySaveError(
|
|
48
|
+
'postType',
|
|
49
|
+
postType
|
|
50
|
+
),
|
|
51
|
+
isSaving: select( coreStore ).isSavingEntityRecord(
|
|
52
|
+
'postType',
|
|
53
|
+
postType
|
|
54
|
+
),
|
|
55
|
+
} ),
|
|
56
|
+
[ postType ]
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
const { saveEntityRecord } = useDispatch( coreStore );
|
|
60
|
+
|
|
61
|
+
async function createPage( event ) {
|
|
62
|
+
event.preventDefault();
|
|
63
|
+
if ( isSaving || ! isTitleValid ) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
const savedRecord = await saveEntityRecord(
|
|
69
|
+
'postType',
|
|
70
|
+
postType,
|
|
71
|
+
{
|
|
72
|
+
title,
|
|
73
|
+
status: shouldPublish ? 'publish' : 'draft',
|
|
74
|
+
},
|
|
75
|
+
{ throwOnError: true }
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
if ( savedRecord ) {
|
|
79
|
+
// Create the page link object from the saved record
|
|
80
|
+
const pageLink = {
|
|
81
|
+
id: savedRecord.id,
|
|
82
|
+
type: postType,
|
|
83
|
+
title: decodeEntities( savedRecord.title.rendered ),
|
|
84
|
+
url: savedRecord.link,
|
|
85
|
+
kind: 'post-type',
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
onPageCreated( pageLink );
|
|
89
|
+
}
|
|
90
|
+
} catch ( error ) {
|
|
91
|
+
// Error handling is done via the data store selectors
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const isSubmitDisabled = isSaving || ! isTitleValid;
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<DialogWrapper
|
|
99
|
+
className="link-ui-page-creator"
|
|
100
|
+
title={ __( 'Create page' ) }
|
|
101
|
+
description={ __( 'Create a new page to add to your Navigation.' ) }
|
|
102
|
+
onBack={ onBack }
|
|
103
|
+
>
|
|
104
|
+
<VStack className="link-ui-page-creator__inner" spacing={ 4 }>
|
|
105
|
+
<form onSubmit={ createPage }>
|
|
106
|
+
<VStack spacing={ 4 }>
|
|
107
|
+
<TextControl
|
|
108
|
+
__next40pxDefaultSize
|
|
109
|
+
__nextHasNoMarginBottom
|
|
110
|
+
label={ __( 'Title' ) }
|
|
111
|
+
onChange={ setTitle }
|
|
112
|
+
placeholder={ __( 'No title' ) }
|
|
113
|
+
value={ title }
|
|
114
|
+
/>
|
|
115
|
+
|
|
116
|
+
<CheckboxControl
|
|
117
|
+
__nextHasNoMarginBottom
|
|
118
|
+
label={ __( 'Publish immediately' ) }
|
|
119
|
+
help={ __(
|
|
120
|
+
'If unchecked, the page will be created as a draft.'
|
|
121
|
+
) }
|
|
122
|
+
checked={ shouldPublish }
|
|
123
|
+
onChange={ setShouldPublish }
|
|
124
|
+
/>
|
|
125
|
+
|
|
126
|
+
{ lastError && (
|
|
127
|
+
<Notice status="error" isDismissible={ false }>
|
|
128
|
+
{ lastError.message }
|
|
129
|
+
</Notice>
|
|
130
|
+
) }
|
|
131
|
+
|
|
132
|
+
<HStack spacing={ 2 } justify="flex-end">
|
|
133
|
+
<Button
|
|
134
|
+
__next40pxDefaultSize
|
|
135
|
+
variant="tertiary"
|
|
136
|
+
onClick={ onBack }
|
|
137
|
+
disabled={ isSaving }
|
|
138
|
+
accessibleWhenDisabled
|
|
139
|
+
>
|
|
140
|
+
{ __( 'Cancel' ) }
|
|
141
|
+
</Button>
|
|
142
|
+
<Button
|
|
143
|
+
__next40pxDefaultSize
|
|
144
|
+
variant="primary"
|
|
145
|
+
type="submit"
|
|
146
|
+
isBusy={ isSaving }
|
|
147
|
+
aria-disabled={ isSubmitDisabled }
|
|
148
|
+
>
|
|
149
|
+
{ __( 'Create page' ) }
|
|
150
|
+
</Button>
|
|
151
|
+
</HStack>
|
|
152
|
+
</VStack>
|
|
153
|
+
</form>
|
|
154
|
+
</VStack>
|
|
155
|
+
</DialogWrapper>
|
|
156
|
+
);
|
|
157
|
+
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
// Allow these default styles to be overridden by global styles.
|
|
2
|
-
:where(.wp-block-post-comments-form)
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
:where(.wp-block-post-comments-form textarea),
|
|
3
|
+
:where(.wp-block-post-comments-form input:not([type="submit"])) {
|
|
4
|
+
border-width: 1px;
|
|
5
|
+
border-style: solid;
|
|
6
|
+
border-color: $gray-600;
|
|
7
|
+
font-size: 1em;
|
|
8
|
+
font-family: inherit;
|
|
9
|
+
}
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
11
|
+
:where(.wp-block-post-comments-form textarea),
|
|
12
|
+
:where(.wp-block-post-comments-form input:where(:not([type="submit"]):not([type="checkbox"]))) {
|
|
13
|
+
padding: calc(0.667em + 2px); // The extra 2px is added to match outline buttons.
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
.wp-block-post-comments-form {
|
package/src/post-date/index.php
CHANGED
|
@@ -20,19 +20,11 @@ function render_block_core_post_date( $attributes, $content, $block ) {
|
|
|
20
20
|
$classes = array();
|
|
21
21
|
|
|
22
22
|
if (
|
|
23
|
-
isset( $attributes['
|
|
24
|
-
|
|
23
|
+
! isset( $attributes['datetime'] ) && ! (
|
|
24
|
+
isset( $attributes['metadata']['bindings']['datetime']['source'] ) &&
|
|
25
|
+
isset( $attributes['metadata']['bindings']['datetime']['args'] )
|
|
26
|
+
)
|
|
25
27
|
) {
|
|
26
|
-
/*
|
|
27
|
-
* We might be running on a version of WordPress that doesn't support binding the block's `datetime` attribute
|
|
28
|
-
* to a Block Bindings source. In this case, we need to manually set the `datetime` attribute to its correct value.
|
|
29
|
-
* This branch can be removed once the minimum required WordPress version is 6.9 or newer.
|
|
30
|
-
*/
|
|
31
|
-
$source = get_block_bindings_source( $attributes['metadata']['bindings']['datetime']['source'] );
|
|
32
|
-
$source_args = $attributes['metadata']['bindings']['datetime']['args'];
|
|
33
|
-
|
|
34
|
-
$attributes['datetime'] = $source->get_value( $source_args, $block, 'datetime' );
|
|
35
|
-
} elseif ( ! isset( $attributes['datetime'] ) ) {
|
|
36
28
|
/*
|
|
37
29
|
* This is the legacy version of the block that didn't have the `datetime` attribute.
|
|
38
30
|
* This branch needs to be kept for backward compatibility.
|
|
@@ -61,7 +53,7 @@ function render_block_core_post_date( $attributes, $content, $block ) {
|
|
|
61
53
|
// (See https://github.com/WordPress/gutenberg/pull/46839 where this logic was originally
|
|
62
54
|
// implemented.)
|
|
63
55
|
// In this case, we have to respect and return the empty value.
|
|
64
|
-
return
|
|
56
|
+
return '';
|
|
65
57
|
}
|
|
66
58
|
|
|
67
59
|
$unformatted_date = $attributes['datetime'];
|
|
@@ -113,5 +105,18 @@ function register_block_core_post_date() {
|
|
|
113
105
|
'render_callback' => 'render_block_core_post_date',
|
|
114
106
|
)
|
|
115
107
|
);
|
|
108
|
+
|
|
109
|
+
// The following filter can be removed once the minimum required WordPress version is 6.9 or newer.
|
|
110
|
+
add_filter(
|
|
111
|
+
'block_bindings_supported_attributes_core/post-date',
|
|
112
|
+
function ( $attributes ) {
|
|
113
|
+
if ( ! in_array( 'datetime', $attributes, true ) ) {
|
|
114
|
+
$attributes[] = 'datetime';
|
|
115
|
+
}
|
|
116
|
+
return $attributes;
|
|
117
|
+
},
|
|
118
|
+
10,
|
|
119
|
+
3
|
|
120
|
+
);
|
|
116
121
|
}
|
|
117
122
|
add_action( 'init', 'register_block_core_post_date' );
|