@wordpress/edit-site 6.0.1 → 6.1.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 +2 -0
- package/build/components/add-new-page/index.js +2 -1
- package/build/components/add-new-page/index.js.map +1 -1
- package/build/components/app/index.js +17 -1
- package/build/components/app/index.js.map +1 -1
- package/build/components/editor/index.js +3 -10
- package/build/components/editor/index.js.map +1 -1
- package/build/components/global-styles/font-library-modal/installed-fonts.js +1 -0
- package/build/components/global-styles/font-library-modal/installed-fonts.js.map +1 -1
- package/build/components/global-styles/screen-revisions/index.js +4 -23
- package/build/components/global-styles/screen-revisions/index.js.map +1 -1
- package/build/components/global-styles/shadows-edit-panel.js +1 -0
- package/build/components/global-styles/shadows-edit-panel.js.map +1 -1
- package/build/components/global-styles/variations/variation.js +11 -16
- package/build/components/global-styles/variations/variation.js.map +1 -1
- package/build/components/global-styles/variations/variations-color.js +1 -0
- package/build/components/global-styles/variations/variations-color.js.map +1 -1
- package/build/components/global-styles/variations/variations-typography.js +1 -0
- package/build/components/global-styles/variations/variations-typography.js.map +1 -1
- package/build/components/layout/index.js +8 -37
- package/build/components/layout/index.js.map +1 -1
- package/build/components/page/header.js +1 -0
- package/build/components/page/header.js.map +1 -1
- package/build/components/page-patterns/header.js +2 -1
- package/build/components/page-patterns/header.js.map +1 -1
- package/build/components/posts-app/index.js +50 -0
- package/build/components/posts-app/index.js.map +1 -0
- package/build/components/sidebar-navigation-screen-navigation-menu/delete-confirm-dialog.js +1 -0
- package/build/components/sidebar-navigation-screen-navigation-menu/delete-confirm-dialog.js.map +1 -1
- package/build/hooks/commands/use-set-command-context.js +53 -0
- package/build/hooks/commands/use-set-command-context.js.map +1 -0
- package/build/hooks/push-changes-to-global-styles/index.js +2 -2
- package/build/hooks/push-changes-to-global-styles/index.js.map +1 -1
- package/build/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js +20 -88
- package/build/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js.map +1 -1
- package/build/index.js +15 -2
- package/build/index.js.map +1 -1
- package/build/posts.js +34 -0
- package/build/posts.js.map +1 -0
- package/build-module/components/add-new-page/index.js +2 -1
- package/build-module/components/add-new-page/index.js.map +1 -1
- package/build-module/components/app/index.js +17 -1
- package/build-module/components/app/index.js.map +1 -1
- package/build-module/components/editor/index.js +3 -10
- package/build-module/components/editor/index.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/installed-fonts.js +1 -0
- package/build-module/components/global-styles/font-library-modal/installed-fonts.js.map +1 -1
- package/build-module/components/global-styles/screen-revisions/index.js +4 -23
- package/build-module/components/global-styles/screen-revisions/index.js.map +1 -1
- package/build-module/components/global-styles/shadows-edit-panel.js +1 -0
- package/build-module/components/global-styles/shadows-edit-panel.js.map +1 -1
- package/build-module/components/global-styles/variations/variation.js +11 -16
- package/build-module/components/global-styles/variations/variation.js.map +1 -1
- package/build-module/components/global-styles/variations/variations-color.js +1 -0
- package/build-module/components/global-styles/variations/variations-color.js.map +1 -1
- package/build-module/components/global-styles/variations/variations-typography.js +1 -0
- package/build-module/components/global-styles/variations/variations-typography.js.map +1 -1
- package/build-module/components/layout/index.js +10 -39
- package/build-module/components/layout/index.js.map +1 -1
- package/build-module/components/page/header.js +1 -0
- package/build-module/components/page/header.js.map +1 -1
- package/build-module/components/page-patterns/header.js +2 -1
- package/build-module/components/page-patterns/header.js.map +1 -1
- package/build-module/components/posts-app/index.js +43 -0
- package/build-module/components/posts-app/index.js.map +1 -0
- package/build-module/components/sidebar-navigation-screen-navigation-menu/delete-confirm-dialog.js +1 -0
- package/build-module/components/sidebar-navigation-screen-navigation-menu/delete-confirm-dialog.js.map +1 -1
- package/build-module/hooks/commands/use-set-command-context.js +46 -0
- package/build-module/hooks/commands/use-set-command-context.js.map +1 -0
- package/build-module/hooks/push-changes-to-global-styles/index.js +2 -2
- package/build-module/hooks/push-changes-to-global-styles/index.js.map +1 -1
- package/build-module/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js +19 -86
- package/build-module/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js.map +1 -1
- package/build-module/index.js +8 -2
- package/build-module/index.js.map +1 -1
- package/build-module/posts.js +27 -0
- package/build-module/posts.js.map +1 -0
- package/build-style/posts-rtl.css +1707 -0
- package/build-style/posts.css +1707 -0
- package/build-style/style-rtl.css +16 -19
- package/build-style/style.css +16 -19
- package/package.json +41 -41
- package/src/components/add-new-page/index.js +2 -1
- package/src/components/app/index.js +17 -1
- package/src/components/editor/index.js +2 -8
- package/src/components/global-styles/font-library-modal/installed-fonts.js +1 -0
- package/src/components/global-styles/screen-revisions/index.js +4 -24
- package/src/components/global-styles/shadows-edit-panel.js +1 -0
- package/src/components/global-styles/style.scss +1 -7
- package/src/components/global-styles/variations/variation.js +14 -19
- package/src/components/global-styles/variations/variations-color.js +6 -1
- package/src/components/global-styles/variations/variations-typography.js +5 -1
- package/src/components/global-styles-sidebar/style.scss +0 -1
- package/src/components/layout/index.js +24 -70
- package/src/components/page/header.js +1 -0
- package/src/components/page/style.scss +6 -0
- package/src/components/page-patterns/header.js +8 -2
- package/src/components/page-patterns/style.scss +6 -0
- package/src/components/posts-app/index.js +39 -0
- package/src/components/sidebar/style.scss +4 -4
- package/src/components/sidebar-navigation-screen-navigation-menu/delete-confirm-dialog.js +1 -0
- package/src/hooks/commands/use-set-command-context.js +37 -0
- package/src/hooks/push-changes-to-global-styles/index.js +2 -2
- package/src/hooks/use-theme-style-variations/test/use-theme-style-variations-by-property.js +1 -875
- package/src/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js +29 -117
- package/src/index.js +10 -2
- package/src/posts.js +29 -0
- package/src/posts.scss +46 -0
- package/build/components/block-editor/block-inspector-button.js +0 -57
- package/build/components/block-editor/block-inspector-button.js.map +0 -1
- package/build/components/block-editor/inserter-media-categories.js +0 -183
- package/build/components/block-editor/inserter-media-categories.js.map +0 -1
- package/build/components/template-part-converter/convert-to-regular.js +0 -38
- package/build/components/template-part-converter/convert-to-regular.js.map +0 -1
- package/build/components/template-part-converter/convert-to-template-part.js +0 -84
- package/build/components/template-part-converter/convert-to-template-part.js.map +0 -1
- package/build/components/template-part-converter/index.js +0 -67
- package/build/components/template-part-converter/index.js.map +0 -1
- package/build-module/components/block-editor/block-inspector-button.js +0 -50
- package/build-module/components/block-editor/block-inspector-button.js.map +0 -1
- package/build-module/components/block-editor/inserter-media-categories.js +0 -177
- package/build-module/components/block-editor/inserter-media-categories.js.map +0 -1
- package/build-module/components/template-part-converter/convert-to-regular.js +0 -31
- package/build-module/components/template-part-converter/convert-to-regular.js.map +0 -1
- package/build-module/components/template-part-converter/convert-to-template-part.js +0 -79
- package/build-module/components/template-part-converter/convert-to-template-part.js.map +0 -1
- package/build-module/components/template-part-converter/index.js +0 -59
- package/build-module/components/template-part-converter/index.js.map +0 -1
- package/src/components/block-editor/block-inspector-button.js +0 -60
- package/src/components/block-editor/inserter-media-categories.js +0 -225
- package/src/components/template-part-converter/convert-to-regular.js +0 -32
- package/src/components/template-part-converter/convert-to-template-part.js +0 -78
- package/src/components/template-part-converter/index.js +0 -59
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { __ } from '@wordpress/i18n';
|
|
5
|
-
import { speak } from '@wordpress/a11y';
|
|
6
|
-
import { MenuItem } from '@wordpress/components';
|
|
7
|
-
import { useSelect, useDispatch } from '@wordpress/data';
|
|
8
|
-
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
|
|
9
|
-
import { privateApis as editorPrivateApis } from '@wordpress/editor';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Internal dependencies
|
|
13
|
-
*/
|
|
14
|
-
import { unlock } from '../../lock-unlock';
|
|
15
|
-
|
|
16
|
-
const { interfaceStore } = unlock( editorPrivateApis );
|
|
17
|
-
|
|
18
|
-
export default function BlockInspectorButton( { onClick = () => {} } ) {
|
|
19
|
-
const { shortcut, isBlockInspectorOpen } = useSelect(
|
|
20
|
-
( select ) => ( {
|
|
21
|
-
shortcut: select(
|
|
22
|
-
keyboardShortcutsStore
|
|
23
|
-
).getShortcutRepresentation( 'core/editor/toggle-sidebar' ),
|
|
24
|
-
isBlockInspectorOpen:
|
|
25
|
-
select( interfaceStore ).getActiveComplementaryArea(
|
|
26
|
-
'core'
|
|
27
|
-
) === 'edit-post/block',
|
|
28
|
-
} ),
|
|
29
|
-
[]
|
|
30
|
-
);
|
|
31
|
-
const { enableComplementaryArea, disableComplementaryArea } =
|
|
32
|
-
useDispatch( interfaceStore );
|
|
33
|
-
|
|
34
|
-
const label = isBlockInspectorOpen
|
|
35
|
-
? __( 'Hide more settings' )
|
|
36
|
-
: __( 'Show more settings' );
|
|
37
|
-
|
|
38
|
-
return (
|
|
39
|
-
<MenuItem
|
|
40
|
-
onClick={ () => {
|
|
41
|
-
if ( isBlockInspectorOpen ) {
|
|
42
|
-
disableComplementaryArea( 'core' );
|
|
43
|
-
speak( __( 'Block settings closed' ) );
|
|
44
|
-
} else {
|
|
45
|
-
enableComplementaryArea( 'core', 'edit-post/block' );
|
|
46
|
-
speak(
|
|
47
|
-
__(
|
|
48
|
-
'Additional settings are now available in the Editor block settings sidebar'
|
|
49
|
-
)
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
// Close dropdown menu.
|
|
53
|
-
onClick();
|
|
54
|
-
} }
|
|
55
|
-
shortcut={ shortcut }
|
|
56
|
-
>
|
|
57
|
-
{ label }
|
|
58
|
-
</MenuItem>
|
|
59
|
-
);
|
|
60
|
-
}
|
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The `edit-site` settings here need to be in sync with the corresponding ones in `site-editor` package.
|
|
3
|
-
* See `packages/edit-site/src/components/block-editor/inserter-media-categories.js`.
|
|
4
|
-
*
|
|
5
|
-
* In the future we could consider creating an Openvese package that can be used in both `editor` and `site-editor`.
|
|
6
|
-
* The rest of the settings would still need to be in sync though.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* WordPress dependencies
|
|
11
|
-
*/
|
|
12
|
-
import { __, sprintf, _x } from '@wordpress/i18n';
|
|
13
|
-
import { resolveSelect } from '@wordpress/data';
|
|
14
|
-
import { decodeEntities } from '@wordpress/html-entities';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Internal dependencies
|
|
18
|
-
*/
|
|
19
|
-
import { store as coreStore } from '@wordpress/core-data';
|
|
20
|
-
|
|
21
|
-
/** @typedef {import('@wordpress/block-editor').InserterMediaRequest} InserterMediaRequest */
|
|
22
|
-
/** @typedef {import('@wordpress/block-editor').InserterMediaItem} InserterMediaItem */
|
|
23
|
-
/** @typedef {import('@wordpress/block-editor').InserterMediaCategory} InserterMediaCategory */
|
|
24
|
-
|
|
25
|
-
const getExternalLink = ( url, text ) =>
|
|
26
|
-
`<a ${ getExternalLinkAttributes( url ) }>${ text }</a>`;
|
|
27
|
-
|
|
28
|
-
const getExternalLinkAttributes = ( url ) =>
|
|
29
|
-
`href="${ url }" target="_blank" rel="noreferrer noopener"`;
|
|
30
|
-
|
|
31
|
-
const getOpenverseLicense = ( license, licenseVersion ) => {
|
|
32
|
-
let licenseName = license.trim();
|
|
33
|
-
// PDM has no abbreviation
|
|
34
|
-
if ( license !== 'pdm' ) {
|
|
35
|
-
licenseName = license.toUpperCase().replace( 'SAMPLING', 'Sampling' );
|
|
36
|
-
}
|
|
37
|
-
// If version is known, append version to the name.
|
|
38
|
-
// The license has to have a version to be valid. Only
|
|
39
|
-
// PDM (public domain mark) doesn't have a version.
|
|
40
|
-
if ( licenseVersion ) {
|
|
41
|
-
licenseName += ` ${ licenseVersion }`;
|
|
42
|
-
}
|
|
43
|
-
// For licenses other than public-domain marks, prepend 'CC' to the name.
|
|
44
|
-
if ( ! [ 'pdm', 'cc0' ].includes( license ) ) {
|
|
45
|
-
licenseName = `CC ${ licenseName }`;
|
|
46
|
-
}
|
|
47
|
-
return licenseName;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const getOpenverseCaption = ( item ) => {
|
|
51
|
-
const {
|
|
52
|
-
title,
|
|
53
|
-
foreign_landing_url: foreignLandingUrl,
|
|
54
|
-
creator,
|
|
55
|
-
creator_url: creatorUrl,
|
|
56
|
-
license,
|
|
57
|
-
license_version: licenseVersion,
|
|
58
|
-
license_url: licenseUrl,
|
|
59
|
-
} = item;
|
|
60
|
-
const fullLicense = getOpenverseLicense( license, licenseVersion );
|
|
61
|
-
const _creator = decodeEntities( creator );
|
|
62
|
-
let _caption;
|
|
63
|
-
if ( _creator ) {
|
|
64
|
-
_caption = title
|
|
65
|
-
? sprintf(
|
|
66
|
-
// translators: %1s: Title of a media work from Openverse; %2s: Name of the work's creator; %3s: Work's licence e.g: "CC0 1.0".
|
|
67
|
-
_x( '"%1$s" by %2$s/ %3$s', 'caption' ),
|
|
68
|
-
getExternalLink(
|
|
69
|
-
foreignLandingUrl,
|
|
70
|
-
decodeEntities( title )
|
|
71
|
-
),
|
|
72
|
-
creatorUrl
|
|
73
|
-
? getExternalLink( creatorUrl, _creator )
|
|
74
|
-
: _creator,
|
|
75
|
-
licenseUrl
|
|
76
|
-
? getExternalLink(
|
|
77
|
-
`${ licenseUrl }?ref=openverse`,
|
|
78
|
-
fullLicense
|
|
79
|
-
)
|
|
80
|
-
: fullLicense
|
|
81
|
-
)
|
|
82
|
-
: sprintf(
|
|
83
|
-
// translators: %1s: Link attributes for a given Openverse media work; %2s: Name of the work's creator; %3s: Works's licence e.g: "CC0 1.0".
|
|
84
|
-
_x( '<a %1$s>Work</a> by %2$s/ %3$s', 'caption' ),
|
|
85
|
-
getExternalLinkAttributes( foreignLandingUrl ),
|
|
86
|
-
creatorUrl
|
|
87
|
-
? getExternalLink( creatorUrl, _creator )
|
|
88
|
-
: _creator,
|
|
89
|
-
licenseUrl
|
|
90
|
-
? getExternalLink(
|
|
91
|
-
`${ licenseUrl }?ref=openverse`,
|
|
92
|
-
fullLicense
|
|
93
|
-
)
|
|
94
|
-
: fullLicense
|
|
95
|
-
);
|
|
96
|
-
} else {
|
|
97
|
-
_caption = title
|
|
98
|
-
? sprintf(
|
|
99
|
-
// translators: %1s: Title of a media work from Openverse; %2s: Work's licence e.g: "CC0 1.0".
|
|
100
|
-
_x( '"%1$s"/ %2$s', 'caption' ),
|
|
101
|
-
getExternalLink(
|
|
102
|
-
foreignLandingUrl,
|
|
103
|
-
decodeEntities( title )
|
|
104
|
-
),
|
|
105
|
-
licenseUrl
|
|
106
|
-
? getExternalLink(
|
|
107
|
-
`${ licenseUrl }?ref=openverse`,
|
|
108
|
-
fullLicense
|
|
109
|
-
)
|
|
110
|
-
: fullLicense
|
|
111
|
-
)
|
|
112
|
-
: sprintf(
|
|
113
|
-
// translators: %1s: Link attributes for a given Openverse media work; %2s: Works's licence e.g: "CC0 1.0".
|
|
114
|
-
_x( '<a %1$s>Work</a>/ %3$s', 'caption' ),
|
|
115
|
-
getExternalLinkAttributes( foreignLandingUrl ),
|
|
116
|
-
licenseUrl
|
|
117
|
-
? getExternalLink(
|
|
118
|
-
`${ licenseUrl }?ref=openverse`,
|
|
119
|
-
fullLicense
|
|
120
|
-
)
|
|
121
|
-
: fullLicense
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
return _caption.replace( /\s{2}/g, ' ' );
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
const coreMediaFetch = async ( query = {} ) => {
|
|
128
|
-
const mediaItems = await resolveSelect( coreStore ).getMediaItems( {
|
|
129
|
-
...query,
|
|
130
|
-
orderBy: !! query?.search ? 'relevance' : 'date',
|
|
131
|
-
} );
|
|
132
|
-
return mediaItems.map( ( mediaItem ) => ( {
|
|
133
|
-
...mediaItem,
|
|
134
|
-
alt: mediaItem.alt_text,
|
|
135
|
-
url: mediaItem.source_url,
|
|
136
|
-
previewUrl: mediaItem.media_details?.sizes?.medium?.source_url,
|
|
137
|
-
caption: mediaItem.caption?.raw,
|
|
138
|
-
} ) );
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
/** @type {InserterMediaCategory[]} */
|
|
142
|
-
const inserterMediaCategories = [
|
|
143
|
-
{
|
|
144
|
-
name: 'images',
|
|
145
|
-
labels: {
|
|
146
|
-
name: __( 'Images' ),
|
|
147
|
-
search_items: __( 'Search images' ),
|
|
148
|
-
},
|
|
149
|
-
mediaType: 'image',
|
|
150
|
-
async fetch( query = {} ) {
|
|
151
|
-
return coreMediaFetch( { ...query, media_type: 'image' } );
|
|
152
|
-
},
|
|
153
|
-
},
|
|
154
|
-
{
|
|
155
|
-
name: 'videos',
|
|
156
|
-
labels: {
|
|
157
|
-
name: __( 'Videos' ),
|
|
158
|
-
search_items: __( 'Search videos' ),
|
|
159
|
-
},
|
|
160
|
-
mediaType: 'video',
|
|
161
|
-
async fetch( query = {} ) {
|
|
162
|
-
return coreMediaFetch( { ...query, media_type: 'video' } );
|
|
163
|
-
},
|
|
164
|
-
},
|
|
165
|
-
{
|
|
166
|
-
name: 'audio',
|
|
167
|
-
labels: {
|
|
168
|
-
name: __( 'Audio' ),
|
|
169
|
-
search_items: __( 'Search audio' ),
|
|
170
|
-
},
|
|
171
|
-
mediaType: 'audio',
|
|
172
|
-
async fetch( query = {} ) {
|
|
173
|
-
return coreMediaFetch( { ...query, media_type: 'audio' } );
|
|
174
|
-
},
|
|
175
|
-
},
|
|
176
|
-
{
|
|
177
|
-
name: 'openverse',
|
|
178
|
-
labels: {
|
|
179
|
-
name: __( 'Openverse' ),
|
|
180
|
-
search_items: __( 'Search Openverse' ),
|
|
181
|
-
},
|
|
182
|
-
mediaType: 'image',
|
|
183
|
-
async fetch( query = {} ) {
|
|
184
|
-
const defaultArgs = {
|
|
185
|
-
mature: false,
|
|
186
|
-
excluded_source: 'flickr,inaturalist,wikimedia',
|
|
187
|
-
license: 'pdm,cc0',
|
|
188
|
-
};
|
|
189
|
-
const finalQuery = { ...query, ...defaultArgs };
|
|
190
|
-
const mapFromInserterMediaRequest = {
|
|
191
|
-
per_page: 'page_size',
|
|
192
|
-
search: 'q',
|
|
193
|
-
};
|
|
194
|
-
const url = new URL( 'https://api.openverse.org/v1/images/' );
|
|
195
|
-
Object.entries( finalQuery ).forEach( ( [ key, value ] ) => {
|
|
196
|
-
const queryKey = mapFromInserterMediaRequest[ key ] || key;
|
|
197
|
-
url.searchParams.set( queryKey, value );
|
|
198
|
-
} );
|
|
199
|
-
const response = await window.fetch( url, {
|
|
200
|
-
headers: {
|
|
201
|
-
'User-Agent': 'WordPress/inserter-media-fetch',
|
|
202
|
-
},
|
|
203
|
-
} );
|
|
204
|
-
const jsonResponse = await response.json();
|
|
205
|
-
const results = jsonResponse.results;
|
|
206
|
-
return results.map( ( result ) => ( {
|
|
207
|
-
...result,
|
|
208
|
-
// This is a temp solution for better titles, until Openverse API
|
|
209
|
-
// completes the cleaning up of some titles of their upstream data.
|
|
210
|
-
title: result.title?.toLowerCase().startsWith( 'file:' )
|
|
211
|
-
? result.title.slice( 5 )
|
|
212
|
-
: result.title,
|
|
213
|
-
sourceId: result.id,
|
|
214
|
-
id: undefined,
|
|
215
|
-
caption: getOpenverseCaption( result ),
|
|
216
|
-
previewUrl: result.thumbnail,
|
|
217
|
-
} ) );
|
|
218
|
-
},
|
|
219
|
-
getReportUrl: ( { sourceId } ) =>
|
|
220
|
-
`https://wordpress.org/openverse/image/${ sourceId }/report/`,
|
|
221
|
-
isExternalResource: true,
|
|
222
|
-
},
|
|
223
|
-
];
|
|
224
|
-
|
|
225
|
-
export default inserterMediaCategories;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { useSelect, useDispatch } from '@wordpress/data';
|
|
5
|
-
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
6
|
-
import { MenuItem } from '@wordpress/components';
|
|
7
|
-
import { __ } from '@wordpress/i18n';
|
|
8
|
-
|
|
9
|
-
export default function ConvertToRegularBlocks( { clientId, onClose } ) {
|
|
10
|
-
const { getBlocks } = useSelect( blockEditorStore );
|
|
11
|
-
const { replaceBlocks } = useDispatch( blockEditorStore );
|
|
12
|
-
|
|
13
|
-
const canRemove = useSelect(
|
|
14
|
-
( select ) => select( blockEditorStore ).canRemoveBlock( clientId ),
|
|
15
|
-
[ clientId ]
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
if ( ! canRemove ) {
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return (
|
|
23
|
-
<MenuItem
|
|
24
|
-
onClick={ () => {
|
|
25
|
-
replaceBlocks( clientId, getBlocks( clientId ) );
|
|
26
|
-
onClose();
|
|
27
|
-
} }
|
|
28
|
-
>
|
|
29
|
-
{ __( 'Detach' ) }
|
|
30
|
-
</MenuItem>
|
|
31
|
-
);
|
|
32
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { useDispatch, useSelect } from '@wordpress/data';
|
|
5
|
-
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
6
|
-
import { MenuItem } from '@wordpress/components';
|
|
7
|
-
import { createBlock } from '@wordpress/blocks';
|
|
8
|
-
import { __ } from '@wordpress/i18n';
|
|
9
|
-
import { useState } from '@wordpress/element';
|
|
10
|
-
import { store as noticesStore } from '@wordpress/notices';
|
|
11
|
-
import { symbolFilled } from '@wordpress/icons';
|
|
12
|
-
import { privateApis as editorPrivateApis } from '@wordpress/editor';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Internal dependencies
|
|
16
|
-
*/
|
|
17
|
-
import { unlock } from '../../lock-unlock';
|
|
18
|
-
import { store as editSiteStore } from '../../store';
|
|
19
|
-
|
|
20
|
-
const { CreateTemplatePartModal } = unlock( editorPrivateApis );
|
|
21
|
-
|
|
22
|
-
export default function ConvertToTemplatePart( { clientIds, blocks } ) {
|
|
23
|
-
const [ isModalOpen, setIsModalOpen ] = useState( false );
|
|
24
|
-
const { replaceBlocks } = useDispatch( blockEditorStore );
|
|
25
|
-
const { createSuccessNotice } = useDispatch( noticesStore );
|
|
26
|
-
|
|
27
|
-
const { canCreate } = useSelect( ( select ) => {
|
|
28
|
-
const { supportsTemplatePartsMode } =
|
|
29
|
-
select( editSiteStore ).getSettings();
|
|
30
|
-
return {
|
|
31
|
-
canCreate: ! supportsTemplatePartsMode,
|
|
32
|
-
};
|
|
33
|
-
}, [] );
|
|
34
|
-
|
|
35
|
-
if ( ! canCreate ) {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const onConvert = async ( templatePart ) => {
|
|
40
|
-
replaceBlocks(
|
|
41
|
-
clientIds,
|
|
42
|
-
createBlock( 'core/template-part', {
|
|
43
|
-
slug: templatePart.slug,
|
|
44
|
-
theme: templatePart.theme,
|
|
45
|
-
} )
|
|
46
|
-
);
|
|
47
|
-
createSuccessNotice( __( 'Template part created.' ), {
|
|
48
|
-
type: 'snackbar',
|
|
49
|
-
} );
|
|
50
|
-
|
|
51
|
-
// The modal and this component will be unmounted because of `replaceBlocks` above,
|
|
52
|
-
// so no need to call `closeModal` or `onClose`.
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
return (
|
|
56
|
-
<>
|
|
57
|
-
<MenuItem
|
|
58
|
-
icon={ symbolFilled }
|
|
59
|
-
onClick={ () => {
|
|
60
|
-
setIsModalOpen( true );
|
|
61
|
-
} }
|
|
62
|
-
aria-expanded={ isModalOpen }
|
|
63
|
-
aria-haspopup="dialog"
|
|
64
|
-
>
|
|
65
|
-
{ __( 'Create template part' ) }
|
|
66
|
-
</MenuItem>
|
|
67
|
-
{ isModalOpen && (
|
|
68
|
-
<CreateTemplatePartModal
|
|
69
|
-
closeModal={ () => {
|
|
70
|
-
setIsModalOpen( false );
|
|
71
|
-
} }
|
|
72
|
-
blocks={ blocks }
|
|
73
|
-
onCreate={ onConvert }
|
|
74
|
-
/>
|
|
75
|
-
) }
|
|
76
|
-
</>
|
|
77
|
-
);
|
|
78
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { useSelect } from '@wordpress/data';
|
|
5
|
-
import {
|
|
6
|
-
BlockSettingsMenuControls,
|
|
7
|
-
store as blockEditorStore,
|
|
8
|
-
} from '@wordpress/block-editor';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Internal dependencies
|
|
12
|
-
*/
|
|
13
|
-
import ConvertToRegularBlocks from './convert-to-regular';
|
|
14
|
-
import ConvertToTemplatePart from './convert-to-template-part';
|
|
15
|
-
|
|
16
|
-
export default function TemplatePartConverter() {
|
|
17
|
-
return (
|
|
18
|
-
<BlockSettingsMenuControls>
|
|
19
|
-
{ ( { selectedClientIds, onClose } ) => (
|
|
20
|
-
<TemplatePartConverterMenuItem
|
|
21
|
-
clientIds={ selectedClientIds }
|
|
22
|
-
onClose={ onClose }
|
|
23
|
-
/>
|
|
24
|
-
) }
|
|
25
|
-
</BlockSettingsMenuControls>
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function TemplatePartConverterMenuItem( { clientIds, onClose } ) {
|
|
30
|
-
const { isContentOnly, blocks } = useSelect(
|
|
31
|
-
( select ) => {
|
|
32
|
-
const { getBlocksByClientId, getBlockEditingMode } =
|
|
33
|
-
select( blockEditorStore );
|
|
34
|
-
return {
|
|
35
|
-
blocks: getBlocksByClientId( clientIds ),
|
|
36
|
-
isContentOnly:
|
|
37
|
-
clientIds.length === 1 &&
|
|
38
|
-
getBlockEditingMode( clientIds[ 0 ] ) === 'contentOnly',
|
|
39
|
-
};
|
|
40
|
-
},
|
|
41
|
-
[ clientIds ]
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
// Do not show the convert button if the block is in content-only mode.
|
|
45
|
-
if ( isContentOnly ) {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Allow converting a single template part to standard blocks.
|
|
50
|
-
if ( blocks.length === 1 && blocks[ 0 ]?.name === 'core/template-part' ) {
|
|
51
|
-
return (
|
|
52
|
-
<ConvertToRegularBlocks
|
|
53
|
-
clientId={ clientIds[ 0 ] }
|
|
54
|
-
onClose={ onClose }
|
|
55
|
-
/>
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
return <ConvertToTemplatePart clientIds={ clientIds } blocks={ blocks } />;
|
|
59
|
-
}
|