@wordpress/core-commands 0.2.0 → 0.3.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/add-post-type-commands.js +4 -14
- package/build/add-post-type-commands.js.map +1 -1
- package/build/site-editor-navigation-commands.js +7 -14
- 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 +4 -11
- 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);
|
|
@@ -49,7 +46,6 @@ const getNavigationCommandLoaderPerPostType = postType => function useNavigation
|
|
|
49
46
|
} = _ref;
|
|
50
47
|
const history = useHistory();
|
|
51
48
|
const supportsSearch = !['wp_template', 'wp_template_part'].includes(postType);
|
|
52
|
-
const deps = supportsSearch ? [search] : [];
|
|
53
49
|
const {
|
|
54
50
|
records,
|
|
55
51
|
isLoading
|
|
@@ -72,7 +68,7 @@ const getNavigationCommandLoaderPerPostType = postType => function useNavigation
|
|
|
72
68
|
/* eslint-disable-next-line @wordpress/data-no-store-string-literals */
|
|
73
69
|
isSiteEditor: !!select('edit-site')
|
|
74
70
|
};
|
|
75
|
-
},
|
|
71
|
+
}, [supportsSearch, search]);
|
|
76
72
|
const commands = (0, _element.useMemo)(() => {
|
|
77
73
|
return (records !== null && records !== void 0 ? records : []).slice(0, 10).map(record => {
|
|
78
74
|
var _getPath, _record$title, _record$title2, _record$title3;
|
|
@@ -82,7 +78,8 @@ const getNavigationCommandLoaderPerPostType = postType => function useNavigation
|
|
|
82
78
|
canvas: (0, _url.getQueryArg)(window.location.href, 'canvas')
|
|
83
79
|
} : {};
|
|
84
80
|
return {
|
|
85
|
-
name:
|
|
81
|
+
name: postType + '-' + record.id,
|
|
82
|
+
searchLabel: ((_record$title = record.title) === null || _record$title === void 0 ? void 0 : _record$title.rendered) + ' ' + record.id,
|
|
86
83
|
label: (_record$title2 = record.title) !== null && _record$title2 !== void 0 && _record$title2.rendered ? (_record$title3 = record.title) === null || _record$title3 === void 0 ? void 0 : _record$title3.rendered : (0, _i18n.__)('(no title)'),
|
|
87
84
|
icon: icons[postType],
|
|
88
85
|
callback: _ref2 => {
|
|
@@ -119,24 +116,20 @@ const useTemplateNavigationCommandLoader = getNavigationCommandLoaderPerPostType
|
|
|
119
116
|
const useTemplatePartNavigationCommandLoader = getNavigationCommandLoaderPerPostType('wp_template_part');
|
|
120
117
|
|
|
121
118
|
function useSiteEditorNavigationCommands() {
|
|
122
|
-
useCommandLoader({
|
|
119
|
+
(0, _commands.useCommandLoader)({
|
|
123
120
|
name: 'core/edit-site/navigate-pages',
|
|
124
|
-
group: (0, _i18n.__)('Pages'),
|
|
125
121
|
hook: usePageNavigationCommandLoader
|
|
126
122
|
});
|
|
127
|
-
useCommandLoader({
|
|
123
|
+
(0, _commands.useCommandLoader)({
|
|
128
124
|
name: 'core/edit-site/navigate-posts',
|
|
129
|
-
group: (0, _i18n.__)('Posts'),
|
|
130
125
|
hook: usePostNavigationCommandLoader
|
|
131
126
|
});
|
|
132
|
-
useCommandLoader({
|
|
127
|
+
(0, _commands.useCommandLoader)({
|
|
133
128
|
name: 'core/edit-site/navigate-templates',
|
|
134
|
-
group: (0, _i18n.__)('Templates'),
|
|
135
129
|
hook: useTemplateNavigationCommandLoader
|
|
136
130
|
});
|
|
137
|
-
useCommandLoader({
|
|
131
|
+
(0, _commands.useCommandLoader)({
|
|
138
132
|
name: 'core/edit-site/navigate-template-parts',
|
|
139
|
-
group: (0, _i18n.__)('Template Parts'),
|
|
140
133
|
hook: useTemplatePartNavigationCommandLoader
|
|
141
134
|
});
|
|
142
135
|
}
|
|
@@ -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,OAAkD;AAAA,MAAb;AAAEC,IAAAA;AAAF,GAAa;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,CAAnC;AACA,UAAMC,KAAK,GAAGP,cAAc,GACzB;AACAF,MAAAA,MAAM,EAAE,CAAC,CAAEA,MAAH,GAAYA,MAAZ,GAAqBU,SAD7B;AAEAC,MAAAA,QAAQ,EAAE,EAFV;AAGAC,MAAAA,OAAO,EAAEZ,MAAM,GAAG,WAAH,GAAiB;AAHhC,KADyB,GAMzB;AACAW,MAAAA,QAAQ,EAAE,CAAC;AADX,KANH;AASA,WAAO;AACNP,MAAAA,OAAO,EAAEG,gBAAgB,CAAE,UAAF,EAAcT,QAAd,EAAwB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1B,gBAAMC,IAAI,GAAG;AACZnC,YAAAA,QADY;AAEZoC,YAAAA,MAAM,EAAEhB,MAAM,CAACO,EAFH;AAGZ,eAAGH;AAHS,WAAb;AAKA,gBAAMa,SAAS,GAAG,uBACjB,iBADiB,EAEjBF,IAFiB,CAAlB;;AAIA,cAAKnB,YAAL,EAAoB;AACnBb,YAAAA,OAAO,CAACmC,IAAR,CAAcH,IAAd;AACA,WAFD,MAEO;AACNI,YAAAA,QAAQ,CAACjB,QAAT,GAAoBe,SAApB;AACA;;AACDH,UAAAA,KAAK;AACL;AAvBK,OAAP;AAyBA,KAhCM,CAAP;AAiCA,GAlCgB,EAkCd,CAAE5B,OAAF,EAAWH,OAAX,CAlCc,CAAjB;AAoCA,SAAO;AACNc,IAAAA,QADM;AAENV,IAAAA;AAFM,GAAP;AAIA,CAxEF;;AA0EA,MAAMiC,8BAA8B,GACnCzC,qCAAqC,CAAE,MAAF,CADtC;AAEA,MAAM0C,8BAA8B,GACnC1C,qCAAqC,CAAE,MAAF,CADtC;AAEA,MAAM2C,kCAAkC,GACvC3C,qCAAqC,CAAE,aAAF,CADtC;AAEA,MAAM4C,sCAAsC,GAC3C5C,qCAAqC,CAAE,kBAAF,CADtC;;AAGO,SAAS6C,+BAAT,GAA2C;AACjD,kCAAkB;AACjBlB,IAAAA,IAAI,EAAE,+BADW;AAEjBmB,IAAAA,IAAI,EAAEL;AAFW,GAAlB;AAIA,kCAAkB;AACjBd,IAAAA,IAAI,EAAE,+BADW;AAEjBmB,IAAAA,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);
|
|
@@ -33,7 +30,6 @@ const getNavigationCommandLoaderPerPostType = postType => function useNavigation
|
|
|
33
30
|
} = _ref;
|
|
34
31
|
const history = useHistory();
|
|
35
32
|
const supportsSearch = !['wp_template', 'wp_template_part'].includes(postType);
|
|
36
|
-
const deps = supportsSearch ? [search] : [];
|
|
37
33
|
const {
|
|
38
34
|
records,
|
|
39
35
|
isLoading
|
|
@@ -56,7 +52,7 @@ const getNavigationCommandLoaderPerPostType = postType => function useNavigation
|
|
|
56
52
|
/* eslint-disable-next-line @wordpress/data-no-store-string-literals */
|
|
57
53
|
isSiteEditor: !!select('edit-site')
|
|
58
54
|
};
|
|
59
|
-
},
|
|
55
|
+
}, [supportsSearch, search]);
|
|
60
56
|
const commands = useMemo(() => {
|
|
61
57
|
return (records !== null && records !== void 0 ? records : []).slice(0, 10).map(record => {
|
|
62
58
|
var _getPath, _record$title, _record$title2, _record$title3;
|
|
@@ -66,7 +62,8 @@ const getNavigationCommandLoaderPerPostType = postType => function useNavigation
|
|
|
66
62
|
canvas: getQueryArg(window.location.href, 'canvas')
|
|
67
63
|
} : {};
|
|
68
64
|
return {
|
|
69
|
-
name:
|
|
65
|
+
name: postType + '-' + record.id,
|
|
66
|
+
searchLabel: ((_record$title = record.title) === null || _record$title === void 0 ? void 0 : _record$title.rendered) + ' ' + record.id,
|
|
70
67
|
label: (_record$title2 = record.title) !== null && _record$title2 !== void 0 && _record$title2.rendered ? (_record$title3 = record.title) === null || _record$title3 === void 0 ? void 0 : _record$title3.rendered : __('(no title)'),
|
|
71
68
|
icon: icons[postType],
|
|
72
69
|
callback: _ref2 => {
|
|
@@ -104,22 +101,18 @@ const useTemplatePartNavigationCommandLoader = getNavigationCommandLoaderPerPost
|
|
|
104
101
|
export function useSiteEditorNavigationCommands() {
|
|
105
102
|
useCommandLoader({
|
|
106
103
|
name: 'core/edit-site/navigate-pages',
|
|
107
|
-
group: __('Pages'),
|
|
108
104
|
hook: usePageNavigationCommandLoader
|
|
109
105
|
});
|
|
110
106
|
useCommandLoader({
|
|
111
107
|
name: 'core/edit-site/navigate-posts',
|
|
112
|
-
group: __('Posts'),
|
|
113
108
|
hook: usePostNavigationCommandLoader
|
|
114
109
|
});
|
|
115
110
|
useCommandLoader({
|
|
116
111
|
name: 'core/edit-site/navigate-templates',
|
|
117
|
-
group: __('Templates'),
|
|
118
112
|
hook: useTemplateNavigationCommandLoader
|
|
119
113
|
});
|
|
120
114
|
useCommandLoader({
|
|
121
115
|
name: 'core/edit-site/navigate-template-parts',
|
|
122
|
-
group: __('Template Parts'),
|
|
123
116
|
hook: useTemplatePartNavigationCommandLoader
|
|
124
117
|
});
|
|
125
118
|
}
|
|
@@ -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","useTemplate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AA,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.3.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.5.0",
|
|
31
|
+
"@wordpress/core-data": "^6.11.0",
|
|
32
|
+
"@wordpress/data": "^9.4.0",
|
|
33
|
+
"@wordpress/element": "^5.11.0",
|
|
34
|
+
"@wordpress/i18n": "^4.34.0",
|
|
35
|
+
"@wordpress/icons": "^9.25.0",
|
|
36
|
+
"@wordpress/private-apis": "^0.16.0",
|
|
37
|
+
"@wordpress/router": "^0.3.0",
|
|
38
|
+
"@wordpress/url": "^3.35.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": "c7c79cb11b677adcbf06cf5f8cfb6c5ec1699f19"
|
|
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
|
}
|