@wordpress/core-commands 0.2.0 → 0.4.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/add-post-type-commands.js +4 -14
- package/build/add-post-type-commands.js.map +1 -1
- package/build/site-editor-navigation-commands.js +15 -26
- package/build/site-editor-navigation-commands.js.map +1 -1
- package/build-module/add-post-type-commands.js +3 -11
- package/build-module/add-post-type-commands.js.map +1 -1
- package/build-module/site-editor-navigation-commands.js +12 -23
- package/build-module/site-editor-navigation-commands.js.map +1 -1
- package/package.json +11 -11
- package/src/add-post-type-commands.js +3 -10
- package/src/site-editor-navigation-commands.js +28 -30
package/CHANGELOG.md
CHANGED
|
@@ -11,30 +11,20 @@ var _i18n = require("@wordpress/i18n");
|
|
|
11
11
|
|
|
12
12
|
var _icons = require("@wordpress/icons");
|
|
13
13
|
|
|
14
|
-
var _lockUnlock = require("./lock-unlock");
|
|
15
|
-
|
|
16
14
|
/**
|
|
17
15
|
* WordPress dependencies
|
|
18
16
|
*/
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Internal dependencies
|
|
22
|
-
*/
|
|
23
|
-
const {
|
|
24
|
-
useCommand
|
|
25
|
-
} = (0, _lockUnlock.unlock)(_commands.privateApis);
|
|
26
|
-
|
|
27
17
|
function useAddPostTypeCommands() {
|
|
28
|
-
useCommand({
|
|
29
|
-
name: 'add
|
|
18
|
+
(0, _commands.useCommand)({
|
|
19
|
+
name: 'core/add-new-post',
|
|
30
20
|
label: (0, _i18n.__)('Add new post'),
|
|
31
21
|
icon: _icons.plus,
|
|
32
22
|
callback: () => {
|
|
33
23
|
document.location.href = 'post-new.php';
|
|
34
24
|
}
|
|
35
25
|
});
|
|
36
|
-
useCommand({
|
|
37
|
-
name: 'add
|
|
26
|
+
(0, _commands.useCommand)({
|
|
27
|
+
name: 'core/add-new-page',
|
|
38
28
|
label: (0, _i18n.__)('Add new page'),
|
|
39
29
|
icon: _icons.plus,
|
|
40
30
|
callback: () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-commands/src/add-post-type-commands.js"],"names":["
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-commands/src/add-post-type-commands.js"],"names":["useAddPostTypeCommands","name","label","icon","plus","callback","document","location","href"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AALA;AACA;AACA;AAKO,SAASA,sBAAT,GAAkC;AACxC,4BAAY;AACXC,IAAAA,IAAI,EAAE,mBADK;AAEXC,IAAAA,KAAK,EAAE,cAAI,cAAJ,CAFI;AAGXC,IAAAA,IAAI,EAAEC,WAHK;AAIXC,IAAAA,QAAQ,EAAE,MAAM;AACfC,MAAAA,QAAQ,CAACC,QAAT,CAAkBC,IAAlB,GAAyB,cAAzB;AACA;AANU,GAAZ;AAQA,4BAAY;AACXP,IAAAA,IAAI,EAAE,mBADK;AAEXC,IAAAA,KAAK,EAAE,cAAI,cAAJ,CAFI;AAGXC,IAAAA,IAAI,EAAEC,WAHK;AAIXC,IAAAA,QAAQ,EAAE,MAAM;AACfC,MAAAA,QAAQ,CAACC,QAAT,CAAkBC,IAAlB,GAAyB,6BAAzB;AACA;AANU,GAAZ;AAQA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCommand } from '@wordpress/commands';\nimport { __ } from '@wordpress/i18n';\nimport { plus } from '@wordpress/icons';\n\nexport function useAddPostTypeCommands() {\n\tuseCommand( {\n\t\tname: 'core/add-new-post',\n\t\tlabel: __( 'Add new post' ),\n\t\ticon: plus,\n\t\tcallback: () => {\n\t\t\tdocument.location.href = 'post-new.php';\n\t\t},\n\t} );\n\tuseCommand( {\n\t\tname: 'core/add-new-page',\n\t\tlabel: __( 'Add new page' ),\n\t\ticon: plus,\n\t\tcallback: () => {\n\t\t\tdocument.location.href = 'post-new.php?post_type=page';\n\t\t},\n\t} );\n}\n"]}
|
|
@@ -30,9 +30,6 @@ var _lockUnlock = require("./lock-unlock");
|
|
|
30
30
|
/**
|
|
31
31
|
* Internal dependencies
|
|
32
32
|
*/
|
|
33
|
-
const {
|
|
34
|
-
useCommandLoader
|
|
35
|
-
} = (0, _lockUnlock.unlock)(_commands.privateApis);
|
|
36
33
|
const {
|
|
37
34
|
useHistory
|
|
38
35
|
} = (0, _lockUnlock.unlock)(_router.privateApis);
|
|
@@ -43,13 +40,11 @@ const icons = {
|
|
|
43
40
|
wp_template_part: _icons.symbolFilled
|
|
44
41
|
};
|
|
45
42
|
|
|
46
|
-
const getNavigationCommandLoaderPerPostType = postType => function useNavigationCommandLoader(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
} = _ref;
|
|
43
|
+
const getNavigationCommandLoaderPerPostType = postType => function useNavigationCommandLoader({
|
|
44
|
+
search
|
|
45
|
+
}) {
|
|
50
46
|
const history = useHistory();
|
|
51
47
|
const supportsSearch = !['wp_template', 'wp_template_part'].includes(postType);
|
|
52
|
-
const deps = supportsSearch ? [search] : [];
|
|
53
48
|
const {
|
|
54
49
|
records,
|
|
55
50
|
isLoading
|
|
@@ -72,23 +67,21 @@ const getNavigationCommandLoaderPerPostType = postType => function useNavigation
|
|
|
72
67
|
/* eslint-disable-next-line @wordpress/data-no-store-string-literals */
|
|
73
68
|
isSiteEditor: !!select('edit-site')
|
|
74
69
|
};
|
|
75
|
-
},
|
|
70
|
+
}, [supportsSearch, search]);
|
|
76
71
|
const commands = (0, _element.useMemo)(() => {
|
|
77
72
|
return (records !== null && records !== void 0 ? records : []).slice(0, 10).map(record => {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const isSiteEditor = (_getPath = (0, _url.getPath)(window.location.href)) === null || _getPath === void 0 ? void 0 : _getPath.includes('site-editor.php');
|
|
73
|
+
const isSiteEditor = (0, _url.getPath)(window.location.href)?.includes('site-editor.php');
|
|
81
74
|
const extraArgs = isSiteEditor ? {
|
|
82
75
|
canvas: (0, _url.getQueryArg)(window.location.href, 'canvas')
|
|
83
76
|
} : {};
|
|
84
77
|
return {
|
|
85
|
-
name:
|
|
86
|
-
|
|
78
|
+
name: postType + '-' + record.id,
|
|
79
|
+
searchLabel: record.title?.rendered + ' ' + record.id,
|
|
80
|
+
label: record.title?.rendered ? record.title?.rendered : (0, _i18n.__)('(no title)'),
|
|
87
81
|
icon: icons[postType],
|
|
88
|
-
callback:
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
} = _ref2;
|
|
82
|
+
callback: ({
|
|
83
|
+
close
|
|
84
|
+
}) => {
|
|
92
85
|
const args = {
|
|
93
86
|
postType,
|
|
94
87
|
postId: record.id,
|
|
@@ -119,24 +112,20 @@ const useTemplateNavigationCommandLoader = getNavigationCommandLoaderPerPostType
|
|
|
119
112
|
const useTemplatePartNavigationCommandLoader = getNavigationCommandLoaderPerPostType('wp_template_part');
|
|
120
113
|
|
|
121
114
|
function useSiteEditorNavigationCommands() {
|
|
122
|
-
useCommandLoader({
|
|
115
|
+
(0, _commands.useCommandLoader)({
|
|
123
116
|
name: 'core/edit-site/navigate-pages',
|
|
124
|
-
group: (0, _i18n.__)('Pages'),
|
|
125
117
|
hook: usePageNavigationCommandLoader
|
|
126
118
|
});
|
|
127
|
-
useCommandLoader({
|
|
119
|
+
(0, _commands.useCommandLoader)({
|
|
128
120
|
name: 'core/edit-site/navigate-posts',
|
|
129
|
-
group: (0, _i18n.__)('Posts'),
|
|
130
121
|
hook: usePostNavigationCommandLoader
|
|
131
122
|
});
|
|
132
|
-
useCommandLoader({
|
|
123
|
+
(0, _commands.useCommandLoader)({
|
|
133
124
|
name: 'core/edit-site/navigate-templates',
|
|
134
|
-
group: (0, _i18n.__)('Templates'),
|
|
135
125
|
hook: useTemplateNavigationCommandLoader
|
|
136
126
|
});
|
|
137
|
-
useCommandLoader({
|
|
127
|
+
(0, _commands.useCommandLoader)({
|
|
138
128
|
name: 'core/edit-site/navigate-template-parts',
|
|
139
|
-
group: (0, _i18n.__)('Template Parts'),
|
|
140
129
|
hook: useTemplatePartNavigationCommandLoader
|
|
141
130
|
});
|
|
142
131
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-commands/src/site-editor-navigation-commands.js"],"names":["
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-commands/src/site-editor-navigation-commands.js"],"names":["useHistory","routerPrivateApis","icons","post","page","wp_template","layout","wp_template_part","symbolFilled","getNavigationCommandLoaderPerPostType","postType","useNavigationCommandLoader","search","history","supportsSearch","includes","records","isLoading","select","getEntityRecords","coreStore","query","undefined","per_page","orderby","hasFinishedResolution","isSiteEditor","commands","slice","map","record","window","location","href","extraArgs","canvas","name","id","searchLabel","title","rendered","label","icon","callback","close","args","postId","targetUrl","push","document","usePageNavigationCommandLoader","usePostNavigationCommandLoader","useTemplateNavigationCommandLoader","useTemplatePartNavigationCommandLoader","useSiteEditorNavigationCommands","hook"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AAfA;AACA;AACA;;AAUA;AACA;AACA;AAGA,MAAM;AAAEA,EAAAA;AAAF,IAAiB,wBAAQC,mBAAR,CAAvB;AAEA,MAAMC,KAAK,GAAG;AACbC,EAAAA,IAAI,EAAJA,WADa;AAEbC,EAAAA,IAAI,EAAJA,WAFa;AAGbC,EAAAA,WAAW,EAAEC,aAHA;AAIbC,EAAAA,gBAAgB,EAAEC;AAJL,CAAd;;AAOA,MAAMC,qCAAqC,GAAKC,QAAF,IAC7C,SAASC,0BAAT,CAAqC;AAAEC,EAAAA;AAAF,CAArC,EAAkD;AACjD,QAAMC,OAAO,GAAGb,UAAU,EAA1B;AACA,QAAMc,cAAc,GAAG,CAAE,CAAE,aAAF,EAAiB,kBAAjB,EAAsCC,QAAtC,CACxBL,QADwB,CAAzB;AAGA,QAAM;AAAEM,IAAAA,OAAF;AAAWC,IAAAA;AAAX,MAAyB,qBAC5BC,MAAF,IAAc;AACb,UAAM;AAAEC,MAAAA;AAAF,QAAuBD,MAAM,CAAEE,eAAF,C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AA,IAAI,EAAEJ;AAFW,GAAlB;AAIA,kCAAkB;AACjBf,IAAAA,IAAI,EAAE,mCADW;AAEjBmB,IAAAA,IAAI,EAAEH;AAFW,GAAlB;AAIA,kCAAkB;AACjBhB,IAAAA,IAAI,EAAE,wCADW;AAEjBmB,IAAAA,IAAI,EAAEF;AAFW,GAAlB;AAIA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCommandLoader } from '@wordpress/commands';\nimport { __ } from '@wordpress/i18n';\nimport { useMemo } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { post, page, layout, symbolFilled } from '@wordpress/icons';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { getQueryArg, addQueryArgs, getPath } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from './lock-unlock';\n\nconst { useHistory } = unlock( routerPrivateApis );\n\nconst icons = {\n\tpost,\n\tpage,\n\twp_template: layout,\n\twp_template_part: symbolFilled,\n};\n\nconst getNavigationCommandLoaderPerPostType = ( postType ) =>\n\tfunction useNavigationCommandLoader( { search } ) {\n\t\tconst history = useHistory();\n\t\tconst supportsSearch = ! [ 'wp_template', 'wp_template_part' ].includes(\n\t\t\tpostType\n\t\t);\n\t\tconst { records, isLoading } = useSelect(\n\t\t\t( select ) => {\n\t\t\t\tconst { getEntityRecords } = select( coreStore );\n\t\t\t\tconst query = supportsSearch\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tsearch: !! search ? search : undefined,\n\t\t\t\t\t\t\tper_page: 10,\n\t\t\t\t\t\t\torderby: search ? 'relevance' : 'date',\n\t\t\t\t\t }\n\t\t\t\t\t: {\n\t\t\t\t\t\t\tper_page: -1,\n\t\t\t\t\t };\n\t\t\t\treturn {\n\t\t\t\t\trecords: getEntityRecords( 'postType', postType, query ),\n\t\t\t\t\tisLoading: ! select( coreStore ).hasFinishedResolution(\n\t\t\t\t\t\t'getEntityRecords',\n\t\t\t\t\t\t[ 'postType', postType, query ]\n\t\t\t\t\t),\n\t\t\t\t\t// We're using the string literal to check whether we're in the site editor.\n\t\t\t\t\t/* eslint-disable-next-line @wordpress/data-no-store-string-literals */\n\t\t\t\t\tisSiteEditor: !! select( 'edit-site' ),\n\t\t\t\t};\n\t\t\t},\n\t\t\t[ supportsSearch, search ]\n\t\t);\n\n\t\tconst commands = useMemo( () => {\n\t\t\treturn ( records ?? [] ).slice( 0, 10 ).map( ( record ) => {\n\t\t\t\tconst isSiteEditor = getPath( window.location.href )?.includes(\n\t\t\t\t\t'site-editor.php'\n\t\t\t\t);\n\t\t\t\tconst extraArgs = isSiteEditor\n\t\t\t\t\t? { canvas: getQueryArg( window.location.href, 'canvas' ) }\n\t\t\t\t\t: {};\n\t\t\t\treturn {\n\t\t\t\t\tname: postType + '-' + record.id,\n\t\t\t\t\tsearchLabel: record.title?.rendered + ' ' + record.id,\n\t\t\t\t\tlabel: record.title?.rendered\n\t\t\t\t\t\t? record.title?.rendered\n\t\t\t\t\t\t: __( '(no title)' ),\n\t\t\t\t\ticon: icons[ postType ],\n\t\t\t\t\tcallback: ( { close } ) => {\n\t\t\t\t\t\tconst args = {\n\t\t\t\t\t\t\tpostType,\n\t\t\t\t\t\t\tpostId: record.id,\n\t\t\t\t\t\t\t...extraArgs,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tconst targetUrl = addQueryArgs(\n\t\t\t\t\t\t\t'site-editor.php',\n\t\t\t\t\t\t\targs\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\t\t\thistory.push( args );\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tclose();\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t} );\n\t\t}, [ records, history ] );\n\n\t\treturn {\n\t\t\tcommands,\n\t\t\tisLoading,\n\t\t};\n\t};\n\nconst usePageNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'page' );\nconst usePostNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'post' );\nconst useTemplateNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'wp_template' );\nconst useTemplatePartNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'wp_template_part' );\n\nexport function useSiteEditorNavigationCommands() {\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-pages',\n\t\thook: usePageNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-posts',\n\t\thook: usePostNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-templates',\n\t\thook: useTemplateNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-template-parts',\n\t\thook: useTemplatePartNavigationCommandLoader,\n\t} );\n}\n"]}
|
|
@@ -1,20 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { useCommand } from '@wordpress/commands';
|
|
5
5
|
import { __ } from '@wordpress/i18n';
|
|
6
6
|
import { plus } from '@wordpress/icons';
|
|
7
|
-
/**
|
|
8
|
-
* Internal dependencies
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { unlock } from './lock-unlock';
|
|
12
|
-
const {
|
|
13
|
-
useCommand
|
|
14
|
-
} = unlock(privateApis);
|
|
15
7
|
export function useAddPostTypeCommands() {
|
|
16
8
|
useCommand({
|
|
17
|
-
name: 'add
|
|
9
|
+
name: 'core/add-new-post',
|
|
18
10
|
label: __('Add new post'),
|
|
19
11
|
icon: plus,
|
|
20
12
|
callback: () => {
|
|
@@ -22,7 +14,7 @@ export function useAddPostTypeCommands() {
|
|
|
22
14
|
}
|
|
23
15
|
});
|
|
24
16
|
useCommand({
|
|
25
|
-
name: 'add
|
|
17
|
+
name: 'core/add-new-page',
|
|
26
18
|
label: __('Add new page'),
|
|
27
19
|
icon: plus,
|
|
28
20
|
callback: () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-commands/src/add-post-type-commands.js"],"names":["
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-commands/src/add-post-type-commands.js"],"names":["useCommand","__","plus","useAddPostTypeCommands","name","label","icon","callback","document","location","href"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,UAAT,QAA2B,qBAA3B;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,IAAT,QAAqB,kBAArB;AAEA,OAAO,SAASC,sBAAT,GAAkC;AACxCH,EAAAA,UAAU,CAAE;AACXI,IAAAA,IAAI,EAAE,mBADK;AAEXC,IAAAA,KAAK,EAAEJ,EAAE,CAAE,cAAF,CAFE;AAGXK,IAAAA,IAAI,EAAEJ,IAHK;AAIXK,IAAAA,QAAQ,EAAE,MAAM;AACfC,MAAAA,QAAQ,CAACC,QAAT,CAAkBC,IAAlB,GAAyB,cAAzB;AACA;AANU,GAAF,CAAV;AAQAV,EAAAA,UAAU,CAAE;AACXI,IAAAA,IAAI,EAAE,mBADK;AAEXC,IAAAA,KAAK,EAAEJ,EAAE,CAAE,cAAF,CAFE;AAGXK,IAAAA,IAAI,EAAEJ,IAHK;AAIXK,IAAAA,QAAQ,EAAE,MAAM;AACfC,MAAAA,QAAQ,CAACC,QAAT,CAAkBC,IAAlB,GAAyB,6BAAzB;AACA;AANU,GAAF,CAAV;AAQA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCommand } from '@wordpress/commands';\nimport { __ } from '@wordpress/i18n';\nimport { plus } from '@wordpress/icons';\n\nexport function useAddPostTypeCommands() {\n\tuseCommand( {\n\t\tname: 'core/add-new-post',\n\t\tlabel: __( 'Add new post' ),\n\t\ticon: plus,\n\t\tcallback: () => {\n\t\t\tdocument.location.href = 'post-new.php';\n\t\t},\n\t} );\n\tuseCommand( {\n\t\tname: 'core/add-new-page',\n\t\tlabel: __( 'Add new page' ),\n\t\ticon: plus,\n\t\tcallback: () => {\n\t\t\tdocument.location.href = 'post-new.php?post_type=page';\n\t\t},\n\t} );\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { useCommandLoader } from '@wordpress/commands';
|
|
5
5
|
import { __ } from '@wordpress/i18n';
|
|
6
6
|
import { useMemo } from '@wordpress/element';
|
|
7
7
|
import { useSelect } from '@wordpress/data';
|
|
@@ -14,9 +14,6 @@ import { getQueryArg, addQueryArgs, getPath } from '@wordpress/url';
|
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
import { unlock } from './lock-unlock';
|
|
17
|
-
const {
|
|
18
|
-
useCommandLoader
|
|
19
|
-
} = unlock(privateApis);
|
|
20
17
|
const {
|
|
21
18
|
useHistory
|
|
22
19
|
} = unlock(routerPrivateApis);
|
|
@@ -27,13 +24,11 @@ const icons = {
|
|
|
27
24
|
wp_template_part: symbolFilled
|
|
28
25
|
};
|
|
29
26
|
|
|
30
|
-
const getNavigationCommandLoaderPerPostType = postType => function useNavigationCommandLoader(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
} = _ref;
|
|
27
|
+
const getNavigationCommandLoaderPerPostType = postType => function useNavigationCommandLoader({
|
|
28
|
+
search
|
|
29
|
+
}) {
|
|
34
30
|
const history = useHistory();
|
|
35
31
|
const supportsSearch = !['wp_template', 'wp_template_part'].includes(postType);
|
|
36
|
-
const deps = supportsSearch ? [search] : [];
|
|
37
32
|
const {
|
|
38
33
|
records,
|
|
39
34
|
isLoading
|
|
@@ -56,23 +51,21 @@ const getNavigationCommandLoaderPerPostType = postType => function useNavigation
|
|
|
56
51
|
/* eslint-disable-next-line @wordpress/data-no-store-string-literals */
|
|
57
52
|
isSiteEditor: !!select('edit-site')
|
|
58
53
|
};
|
|
59
|
-
},
|
|
54
|
+
}, [supportsSearch, search]);
|
|
60
55
|
const commands = useMemo(() => {
|
|
61
56
|
return (records !== null && records !== void 0 ? records : []).slice(0, 10).map(record => {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const isSiteEditor = (_getPath = getPath(window.location.href)) === null || _getPath === void 0 ? void 0 : _getPath.includes('site-editor.php');
|
|
57
|
+
const isSiteEditor = getPath(window.location.href)?.includes('site-editor.php');
|
|
65
58
|
const extraArgs = isSiteEditor ? {
|
|
66
59
|
canvas: getQueryArg(window.location.href, 'canvas')
|
|
67
60
|
} : {};
|
|
68
61
|
return {
|
|
69
|
-
name:
|
|
70
|
-
|
|
62
|
+
name: postType + '-' + record.id,
|
|
63
|
+
searchLabel: record.title?.rendered + ' ' + record.id,
|
|
64
|
+
label: record.title?.rendered ? record.title?.rendered : __('(no title)'),
|
|
71
65
|
icon: icons[postType],
|
|
72
|
-
callback:
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
} = _ref2;
|
|
66
|
+
callback: ({
|
|
67
|
+
close
|
|
68
|
+
}) => {
|
|
76
69
|
const args = {
|
|
77
70
|
postType,
|
|
78
71
|
postId: record.id,
|
|
@@ -104,22 +97,18 @@ const useTemplatePartNavigationCommandLoader = getNavigationCommandLoaderPerPost
|
|
|
104
97
|
export function useSiteEditorNavigationCommands() {
|
|
105
98
|
useCommandLoader({
|
|
106
99
|
name: 'core/edit-site/navigate-pages',
|
|
107
|
-
group: __('Pages'),
|
|
108
100
|
hook: usePageNavigationCommandLoader
|
|
109
101
|
});
|
|
110
102
|
useCommandLoader({
|
|
111
103
|
name: 'core/edit-site/navigate-posts',
|
|
112
|
-
group: __('Posts'),
|
|
113
104
|
hook: usePostNavigationCommandLoader
|
|
114
105
|
});
|
|
115
106
|
useCommandLoader({
|
|
116
107
|
name: 'core/edit-site/navigate-templates',
|
|
117
|
-
group: __('Templates'),
|
|
118
108
|
hook: useTemplateNavigationCommandLoader
|
|
119
109
|
});
|
|
120
110
|
useCommandLoader({
|
|
121
111
|
name: 'core/edit-site/navigate-template-parts',
|
|
122
|
-
group: __('Template Parts'),
|
|
123
112
|
hook: useTemplatePartNavigationCommandLoader
|
|
124
113
|
});
|
|
125
114
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-commands/src/site-editor-navigation-commands.js"],"names":["
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-commands/src/site-editor-navigation-commands.js"],"names":["useCommandLoader","__","useMemo","useSelect","store","coreStore","post","page","layout","symbolFilled","privateApis","routerPrivateApis","getQueryArg","addQueryArgs","getPath","unlock","useHistory","icons","wp_template","wp_template_part","getNavigationCommandLoaderPerPostType","postType","useNavigationCommandLoader","search","history","supportsSearch","includes","records","isLoading","select","getEntityRecords","query","undefined","per_page","orderby","hasFinishedResolution","isSiteEditor","commands","slice","map","record","window","location","href","extraArgs","canvas","name","id","searchLabel","title","rendered","label","icon","callback","close","args","postId","targetUrl","push","document","usePageNavigationCommandLoader","usePostNavigationCommandLoader","useTemplateNavigationCommandLoader","useTemplatePartNavigationCommandLoader","useSiteEditorNavigationCommands","hook"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,gBAAT,QAAiC,qBAAjC;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,OAAT,QAAwB,oBAAxB;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,sBAAnC;AACA,SAASC,IAAT,EAAeC,IAAf,EAAqBC,MAArB,EAA6BC,YAA7B,QAAiD,kBAAjD;AACA,SAASC,WAAW,IAAIC,iBAAxB,QAAiD,mBAAjD;AACA,SAASC,WAAT,EAAsBC,YAAtB,EAAoCC,OAApC,QAAmD,gBAAnD;AAEA;AACA;AACA;;AACA,SAASC,MAAT,QAAuB,eAAvB;AAEA,MAAM;AAAEC,EAAAA;AAAF,IAAiBD,MAAM,CAAEJ,iBAAF,CAA7B;AAEA,MAAMM,KAAK,GAAG;AACbX,EAAAA,IADa;AAE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AE3B,OAAF,EAAWH,OAAX,CAlCqB,CAAxB;AAoCA,SAAO;AACNa,IAAAA,QADM;AAENT,IAAAA;AAFM,GAAP;AAIA,CAxEF;;AA0EA,MAAMgC,8BAA8B,GACnCxC,qCAAqC,CAAE,MAAF,CADtC;AAEA,MAAMyC,8BAA8B,GACnCzC,qCAAqC,CAAE,MAAF,CADtC;AAEA,MAAM0C,kCAAkC,GACvC1C,qCAAqC,CAAE,aAAF,CADtC;AAEA,MAAM2C,sCAAsC,GAC3C3C,qCAAqC,CAAE,kBAAF,CADtC;AAGA,OAAO,SAAS4C,+BAAT,GAA2C;AACjDhE,EAAAA,gBAAgB,CAAE;AACjB8C,IAAAA,IAAI,EAAE,+BADW;AAEjBmB,IAAAA,IAAI,EAAEL;AAFW,GAAF,CAAhB;AAIA5D,EAAAA,gBAAgB,CAAE;AACjB8C,IAAAA,IAAI,EAAE,+BADW;AAEjBmB,IAAAA,IAAI,EAAEJ;AAFW,GAAF,CAAhB;AAIA7D,EAAAA,gBAAgB,CAAE;AACjB8C,IAAAA,IAAI,EAAE,mCADW;AAEjBmB,IAAAA,IAAI,EAAEH;AAFW,GAAF,CAAhB;AAIA9D,EAAAA,gBAAgB,CAAE;AACjB8C,IAAAA,IAAI,EAAE,wCADW;AAEjBmB,IAAAA,IAAI,EAAEF;AAFW,GAAF,CAAhB;AAIA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCommandLoader } from '@wordpress/commands';\nimport { __ } from '@wordpress/i18n';\nimport { useMemo } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { post, page, layout, symbolFilled } from '@wordpress/icons';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { getQueryArg, addQueryArgs, getPath } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from './lock-unlock';\n\nconst { useHistory } = unlock( routerPrivateApis );\n\nconst icons = {\n\tpost,\n\tpage,\n\twp_template: layout,\n\twp_template_part: symbolFilled,\n};\n\nconst getNavigationCommandLoaderPerPostType = ( postType ) =>\n\tfunction useNavigationCommandLoader( { search } ) {\n\t\tconst history = useHistory();\n\t\tconst supportsSearch = ! [ 'wp_template', 'wp_template_part' ].includes(\n\t\t\tpostType\n\t\t);\n\t\tconst { records, isLoading } = useSelect(\n\t\t\t( select ) => {\n\t\t\t\tconst { getEntityRecords } = select( coreStore );\n\t\t\t\tconst query = supportsSearch\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tsearch: !! search ? search : undefined,\n\t\t\t\t\t\t\tper_page: 10,\n\t\t\t\t\t\t\torderby: search ? 'relevance' : 'date',\n\t\t\t\t\t }\n\t\t\t\t\t: {\n\t\t\t\t\t\t\tper_page: -1,\n\t\t\t\t\t };\n\t\t\t\treturn {\n\t\t\t\t\trecords: getEntityRecords( 'postType', postType, query ),\n\t\t\t\t\tisLoading: ! select( coreStore ).hasFinishedResolution(\n\t\t\t\t\t\t'getEntityRecords',\n\t\t\t\t\t\t[ 'postType', postType, query ]\n\t\t\t\t\t),\n\t\t\t\t\t// We're using the string literal to check whether we're in the site editor.\n\t\t\t\t\t/* eslint-disable-next-line @wordpress/data-no-store-string-literals */\n\t\t\t\t\tisSiteEditor: !! select( 'edit-site' ),\n\t\t\t\t};\n\t\t\t},\n\t\t\t[ supportsSearch, search ]\n\t\t);\n\n\t\tconst commands = useMemo( () => {\n\t\t\treturn ( records ?? [] ).slice( 0, 10 ).map( ( record ) => {\n\t\t\t\tconst isSiteEditor = getPath( window.location.href )?.includes(\n\t\t\t\t\t'site-editor.php'\n\t\t\t\t);\n\t\t\t\tconst extraArgs = isSiteEditor\n\t\t\t\t\t? { canvas: getQueryArg( window.location.href, 'canvas' ) }\n\t\t\t\t\t: {};\n\t\t\t\treturn {\n\t\t\t\t\tname: postType + '-' + record.id,\n\t\t\t\t\tsearchLabel: record.title?.rendered + ' ' + record.id,\n\t\t\t\t\tlabel: record.title?.rendered\n\t\t\t\t\t\t? record.title?.rendered\n\t\t\t\t\t\t: __( '(no title)' ),\n\t\t\t\t\ticon: icons[ postType ],\n\t\t\t\t\tcallback: ( { close } ) => {\n\t\t\t\t\t\tconst args = {\n\t\t\t\t\t\t\tpostType,\n\t\t\t\t\t\t\tpostId: record.id,\n\t\t\t\t\t\t\t...extraArgs,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tconst targetUrl = addQueryArgs(\n\t\t\t\t\t\t\t'site-editor.php',\n\t\t\t\t\t\t\targs\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\t\t\thistory.push( args );\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tclose();\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t} );\n\t\t}, [ records, history ] );\n\n\t\treturn {\n\t\t\tcommands,\n\t\t\tisLoading,\n\t\t};\n\t};\n\nconst usePageNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'page' );\nconst usePostNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'post' );\nconst useTemplateNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'wp_template' );\nconst useTemplatePartNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'wp_template_part' );\n\nexport function useSiteEditorNavigationCommands() {\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-pages',\n\t\thook: usePageNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-posts',\n\t\thook: usePostNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-templates',\n\t\thook: useTemplateNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-template-parts',\n\t\thook: useTemplatePartNavigationCommandLoader,\n\t} );\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/core-commands",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "WordPress core reusable commands.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -27,15 +27,15 @@
|
|
|
27
27
|
"sideEffects": false,
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@babel/runtime": "^7.16.0",
|
|
30
|
-
"@wordpress/commands": "^0.
|
|
31
|
-
"@wordpress/core-data": "^6.
|
|
32
|
-
"@wordpress/data": "^9.
|
|
33
|
-
"@wordpress/element": "^5.
|
|
34
|
-
"@wordpress/i18n": "^4.
|
|
35
|
-
"@wordpress/icons": "^9.
|
|
36
|
-
"@wordpress/private-apis": "^0.
|
|
37
|
-
"@wordpress/router": "^0.
|
|
38
|
-
"@wordpress/url": "^3.
|
|
30
|
+
"@wordpress/commands": "^0.6.0",
|
|
31
|
+
"@wordpress/core-data": "^6.12.0",
|
|
32
|
+
"@wordpress/data": "^9.5.0",
|
|
33
|
+
"@wordpress/element": "^5.12.0",
|
|
34
|
+
"@wordpress/i18n": "^4.35.0",
|
|
35
|
+
"@wordpress/icons": "^9.26.0",
|
|
36
|
+
"@wordpress/private-apis": "^0.17.0",
|
|
37
|
+
"@wordpress/router": "^0.4.0",
|
|
38
|
+
"@wordpress/url": "^3.36.0"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"react": "^18.0.0"
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"publishConfig": {
|
|
44
44
|
"access": "public"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "a92f606309b1541b834ff9b0a76ed2a466fc45ed"
|
|
47
47
|
}
|
|
@@ -1,20 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { useCommand } from '@wordpress/commands';
|
|
5
5
|
import { __ } from '@wordpress/i18n';
|
|
6
6
|
import { plus } from '@wordpress/icons';
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* Internal dependencies
|
|
10
|
-
*/
|
|
11
|
-
import { unlock } from './lock-unlock';
|
|
12
|
-
|
|
13
|
-
const { useCommand } = unlock( privateApis );
|
|
14
|
-
|
|
15
8
|
export function useAddPostTypeCommands() {
|
|
16
9
|
useCommand( {
|
|
17
|
-
name: 'add
|
|
10
|
+
name: 'core/add-new-post',
|
|
18
11
|
label: __( 'Add new post' ),
|
|
19
12
|
icon: plus,
|
|
20
13
|
callback: () => {
|
|
@@ -22,7 +15,7 @@ export function useAddPostTypeCommands() {
|
|
|
22
15
|
},
|
|
23
16
|
} );
|
|
24
17
|
useCommand( {
|
|
25
|
-
name: 'add
|
|
18
|
+
name: 'core/add-new-page',
|
|
26
19
|
label: __( 'Add new page' ),
|
|
27
20
|
icon: plus,
|
|
28
21
|
callback: () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { useCommandLoader } from '@wordpress/commands';
|
|
5
5
|
import { __ } from '@wordpress/i18n';
|
|
6
6
|
import { useMemo } from '@wordpress/element';
|
|
7
7
|
import { useSelect } from '@wordpress/data';
|
|
@@ -15,7 +15,6 @@ import { getQueryArg, addQueryArgs, getPath } from '@wordpress/url';
|
|
|
15
15
|
*/
|
|
16
16
|
import { unlock } from './lock-unlock';
|
|
17
17
|
|
|
18
|
-
const { useCommandLoader } = unlock( privateApis );
|
|
19
18
|
const { useHistory } = unlock( routerPrivateApis );
|
|
20
19
|
|
|
21
20
|
const icons = {
|
|
@@ -31,29 +30,31 @@ const getNavigationCommandLoaderPerPostType = ( postType ) =>
|
|
|
31
30
|
const supportsSearch = ! [ 'wp_template', 'wp_template_part' ].includes(
|
|
32
31
|
postType
|
|
33
32
|
);
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
33
|
+
const { records, isLoading } = useSelect(
|
|
34
|
+
( select ) => {
|
|
35
|
+
const { getEntityRecords } = select( coreStore );
|
|
36
|
+
const query = supportsSearch
|
|
37
|
+
? {
|
|
38
|
+
search: !! search ? search : undefined,
|
|
39
|
+
per_page: 10,
|
|
40
|
+
orderby: search ? 'relevance' : 'date',
|
|
41
|
+
}
|
|
42
|
+
: {
|
|
43
|
+
per_page: -1,
|
|
44
|
+
};
|
|
45
|
+
return {
|
|
46
|
+
records: getEntityRecords( 'postType', postType, query ),
|
|
47
|
+
isLoading: ! select( coreStore ).hasFinishedResolution(
|
|
48
|
+
'getEntityRecords',
|
|
49
|
+
[ 'postType', postType, query ]
|
|
50
|
+
),
|
|
51
|
+
// We're using the string literal to check whether we're in the site editor.
|
|
52
|
+
/* eslint-disable-next-line @wordpress/data-no-store-string-literals */
|
|
53
|
+
isSiteEditor: !! select( 'edit-site' ),
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
[ supportsSearch, search ]
|
|
57
|
+
);
|
|
57
58
|
|
|
58
59
|
const commands = useMemo( () => {
|
|
59
60
|
return ( records ?? [] ).slice( 0, 10 ).map( ( record ) => {
|
|
@@ -64,7 +65,8 @@ const getNavigationCommandLoaderPerPostType = ( postType ) =>
|
|
|
64
65
|
? { canvas: getQueryArg( window.location.href, 'canvas' ) }
|
|
65
66
|
: {};
|
|
66
67
|
return {
|
|
67
|
-
name:
|
|
68
|
+
name: postType + '-' + record.id,
|
|
69
|
+
searchLabel: record.title?.rendered + ' ' + record.id,
|
|
68
70
|
label: record.title?.rendered
|
|
69
71
|
? record.title?.rendered
|
|
70
72
|
: __( '(no title)' ),
|
|
@@ -108,22 +110,18 @@ const useTemplatePartNavigationCommandLoader =
|
|
|
108
110
|
export function useSiteEditorNavigationCommands() {
|
|
109
111
|
useCommandLoader( {
|
|
110
112
|
name: 'core/edit-site/navigate-pages',
|
|
111
|
-
group: __( 'Pages' ),
|
|
112
113
|
hook: usePageNavigationCommandLoader,
|
|
113
114
|
} );
|
|
114
115
|
useCommandLoader( {
|
|
115
116
|
name: 'core/edit-site/navigate-posts',
|
|
116
|
-
group: __( 'Posts' ),
|
|
117
117
|
hook: usePostNavigationCommandLoader,
|
|
118
118
|
} );
|
|
119
119
|
useCommandLoader( {
|
|
120
120
|
name: 'core/edit-site/navigate-templates',
|
|
121
|
-
group: __( 'Templates' ),
|
|
122
121
|
hook: useTemplateNavigationCommandLoader,
|
|
123
122
|
} );
|
|
124
123
|
useCommandLoader( {
|
|
125
124
|
name: 'core/edit-site/navigate-template-parts',
|
|
126
|
-
group: __( 'Template Parts' ),
|
|
127
125
|
hook: useTemplatePartNavigationCommandLoader,
|
|
128
126
|
} );
|
|
129
127
|
}
|