@wordpress/core-commands 0.7.0 → 0.8.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/admin-navigation-commands.js +39 -4
- package/build/admin-navigation-commands.js.map +1 -1
- package/build/hooks.js +20 -0
- package/build/hooks.js.map +1 -0
- package/build/site-editor-navigation-commands.js +9 -22
- package/build/site-editor-navigation-commands.js.map +1 -1
- package/build-module/admin-navigation-commands.js +35 -5
- package/build-module/admin-navigation-commands.js.map +1 -1
- package/build-module/hooks.js +10 -0
- package/build-module/hooks.js.map +1 -0
- package/build-module/site-editor-navigation-commands.js +9 -23
- package/build-module/site-editor-navigation-commands.js.map +1 -1
- package/package.json +12 -11
- package/src/admin-navigation-commands.js +34 -5
- package/src/hooks.js +16 -0
- package/src/site-editor-navigation-commands.js +7 -19
package/CHANGELOG.md
CHANGED
|
@@ -11,10 +11,29 @@ var _i18n = require("@wordpress/i18n");
|
|
|
11
11
|
|
|
12
12
|
var _icons = require("@wordpress/icons");
|
|
13
13
|
|
|
14
|
+
var _url = require("@wordpress/url");
|
|
15
|
+
|
|
16
|
+
var _router = require("@wordpress/router");
|
|
17
|
+
|
|
18
|
+
var _hooks = require("./hooks");
|
|
19
|
+
|
|
20
|
+
var _lockUnlock = require("./lock-unlock");
|
|
21
|
+
|
|
14
22
|
/**
|
|
15
23
|
* WordPress dependencies
|
|
16
24
|
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Internal dependencies
|
|
28
|
+
*/
|
|
29
|
+
const {
|
|
30
|
+
useHistory
|
|
31
|
+
} = (0, _lockUnlock.unlock)(_router.privateApis);
|
|
32
|
+
|
|
17
33
|
function useAdminNavigationCommands() {
|
|
34
|
+
const history = useHistory();
|
|
35
|
+
const isSiteEditorAccessible = (0, _hooks.useIsSiteEditorAccessible)();
|
|
36
|
+
const isSiteEditor = (0, _url.getPath)(window.location.href)?.includes('site-editor.php');
|
|
18
37
|
(0, _commands.useCommand)({
|
|
19
38
|
name: 'core/add-new-post',
|
|
20
39
|
label: (0, _i18n.__)('Add new post'),
|
|
@@ -33,11 +52,27 @@ function useAdminNavigationCommands() {
|
|
|
33
52
|
});
|
|
34
53
|
(0, _commands.useCommand)({
|
|
35
54
|
name: 'core/manage-reusable-blocks',
|
|
36
|
-
label: (0, _i18n.__)('
|
|
37
|
-
callback: (
|
|
38
|
-
|
|
55
|
+
label: (0, _i18n.__)('Open patterns'),
|
|
56
|
+
callback: ({
|
|
57
|
+
close
|
|
58
|
+
}) => {
|
|
59
|
+
if (!isSiteEditorAccessible) {
|
|
60
|
+
document.location.href = 'edit.php?post_type=wp_block';
|
|
61
|
+
} else {
|
|
62
|
+
const args = {
|
|
63
|
+
path: '/patterns'
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
if (isSiteEditor) {
|
|
67
|
+
history.push(args);
|
|
68
|
+
} else {
|
|
69
|
+
document.location = (0, _url.addQueryArgs)('site-editor.php', args);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
close();
|
|
73
|
+
}
|
|
39
74
|
},
|
|
40
|
-
icon: _icons.external
|
|
75
|
+
icon: isSiteEditor ? _icons.symbol : _icons.external
|
|
41
76
|
});
|
|
42
77
|
}
|
|
43
78
|
//# sourceMappingURL=admin-navigation-commands.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-commands/src/admin-navigation-commands.js"],"names":["useAdminNavigationCommands","name","label","icon","plus","callback","document","
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-commands/src/admin-navigation-commands.js"],"names":["useHistory","routerPrivateApis","useAdminNavigationCommands","history","isSiteEditorAccessible","isSiteEditor","window","location","href","includes","name","label","icon","plus","callback","document","close","args","path","push","symbol","external"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAbA;AACA;AACA;;AAOA;AACA;AACA;AAIA,MAAM;AAAEA,EAA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DD,QAAAA,KAAK;AACL;AACD,KAjBU;AAkBXJ,IAAAA,IAAI,EAAEP,YAAY,GAAGe,aAAH,GAAYC;AAlBnB,GAAZ;AAoBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCommand } from '@wordpress/commands';\nimport { __ } from '@wordpress/i18n';\nimport { external, plus, symbol } from '@wordpress/icons';\nimport { addQueryArgs, getPath } from '@wordpress/url';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\n\n/**\n * Internal dependencies\n */\nimport { useIsSiteEditorAccessible } from './hooks';\nimport { unlock } from './lock-unlock';\n\nconst { useHistory } = unlock( routerPrivateApis );\n\nexport function useAdminNavigationCommands() {\n\tconst history = useHistory();\n\tconst isSiteEditorAccessible = useIsSiteEditorAccessible();\n\n\tconst isSiteEditor = getPath( window.location.href )?.includes(\n\t\t'site-editor.php'\n\t);\n\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\tuseCommand( {\n\t\tname: 'core/manage-reusable-blocks',\n\t\tlabel: __( 'Open patterns' ),\n\t\tcallback: ( { close } ) => {\n\t\t\tif ( ! isSiteEditorAccessible ) {\n\t\t\t\tdocument.location.href = 'edit.php?post_type=wp_block';\n\t\t\t} else {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/patterns',\n\t\t\t\t};\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = addQueryArgs( 'site-editor.php', args );\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t}\n\t\t},\n\t\ticon: isSiteEditor ? symbol : external,\n\t} );\n}\n"]}
|
package/build/hooks.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useIsSiteEditorAccessible = useIsSiteEditorAccessible;
|
|
7
|
+
|
|
8
|
+
var _blockEditor = require("@wordpress/block-editor");
|
|
9
|
+
|
|
10
|
+
var _coreData = require("@wordpress/core-data");
|
|
11
|
+
|
|
12
|
+
var _data = require("@wordpress/data");
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* WordPress dependencies
|
|
16
|
+
*/
|
|
17
|
+
function useIsSiteEditorAccessible() {
|
|
18
|
+
return (0, _data.useSelect)(select => select(_blockEditor.store).getSettings().__unstableIsBlockBasedTheme && select(_coreData.store).canUser('read', 'templates'), []);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-commands/src/hooks.js"],"names":["useIsSiteEditorAccessible","select","blockEditorStore","getSettings","__unstableIsBlockBasedTheme","coreStore","canUser"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AALA;AACA;AACA;AAKO,SAASA,yBAAT,GAAqC;AAC3C,SAAO,qBACJC,MAAF,IACCA,MAAM,CAAEC,kBAAF,CAAN,CAA2BC,WAA3B,GACEC,2BADF,IAEAH,MAAM,CAAEI,eAAF,CAAN,CAAoBC,OAApB,CAA6B,MAA7B,EAAqC,WAArC,CAJK,EAKN,EALM,CAAP;AAOA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useSelect } from '@wordpress/data';\n\nexport function useIsSiteEditorAccessible() {\n\treturn useSelect(\n\t\t( select ) =>\n\t\t\tselect( blockEditorStore ).getSettings()\n\t\t\t\t.__unstableIsBlockBasedTheme &&\n\t\t\tselect( coreStore ).canUser( 'read', 'templates' ),\n\t\t[]\n\t);\n}\n"]}
|
|
@@ -21,6 +21,8 @@ var _router = require("@wordpress/router");
|
|
|
21
21
|
|
|
22
22
|
var _url = require("@wordpress/url");
|
|
23
23
|
|
|
24
|
+
var _hooks = require("./hooks");
|
|
25
|
+
|
|
24
26
|
var _lockUnlock = require("./lock-unlock");
|
|
25
27
|
|
|
26
28
|
/**
|
|
@@ -111,8 +113,14 @@ const useTemplatePartNavigationCommandLoader = getNavigationCommandLoaderPerPost
|
|
|
111
113
|
function useSiteEditorBasicNavigationCommands() {
|
|
112
114
|
const history = useHistory();
|
|
113
115
|
const isSiteEditor = (0, _url.getPath)(window.location.href)?.includes('site-editor.php');
|
|
116
|
+
const isSiteEditorAccessible = (0, _hooks.useIsSiteEditorAccessible)();
|
|
114
117
|
const commands = (0, _element.useMemo)(() => {
|
|
115
118
|
const result = [];
|
|
119
|
+
|
|
120
|
+
if (!isSiteEditorAccessible) {
|
|
121
|
+
return result;
|
|
122
|
+
}
|
|
123
|
+
|
|
116
124
|
result.push({
|
|
117
125
|
name: 'core/edit-site/open-navigation',
|
|
118
126
|
label: (0, _i18n.__)('Open navigation'),
|
|
@@ -197,29 +205,8 @@ function useSiteEditorBasicNavigationCommands() {
|
|
|
197
205
|
close();
|
|
198
206
|
}
|
|
199
207
|
});
|
|
200
|
-
result.push({
|
|
201
|
-
name: 'core/edit-site/open-template-parts',
|
|
202
|
-
label: (0, _i18n.__)('Open patterns'),
|
|
203
|
-
icon: _icons.symbol,
|
|
204
|
-
callback: ({
|
|
205
|
-
close
|
|
206
|
-
}) => {
|
|
207
|
-
const args = {
|
|
208
|
-
path: '/patterns'
|
|
209
|
-
};
|
|
210
|
-
const targetUrl = (0, _url.addQueryArgs)('site-editor.php', args);
|
|
211
|
-
|
|
212
|
-
if (isSiteEditor) {
|
|
213
|
-
history.push(args);
|
|
214
|
-
} else {
|
|
215
|
-
document.location = targetUrl;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
close();
|
|
219
|
-
}
|
|
220
|
-
});
|
|
221
208
|
return result;
|
|
222
|
-
}, [history, isSiteEditor]);
|
|
209
|
+
}, [history, isSiteEditor, isSiteEditorAccessible]);
|
|
223
210
|
return {
|
|
224
211
|
commands,
|
|
225
212
|
isLoading: false
|
|
@@ -1 +1 @@
|
|
|
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","status","hasFinishedResolution","commands","slice","map","record","isSiteEditor","window","location","href","extraArgs","canvas","name","id","searchLabel","title","rendered","label","icon","callback","close","args","postId","targetUrl","push","document","usePageNavigationCommandLoader","usePostNavigationCommandLoader","useTemplateNavigationCommandLoader","useTemplatePartNavigationCommandLoader","useSiteEditorBasicNavigationCommands","result","navigation","path","styles","symbol","useSiteEditorNavigationCommands","hook","context"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AASA;;AACA;;AAKA;;AAvBA;AACA;AACA;;AAkBA;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,QA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AE,cAAI,eAAJ,CAFK;AAGZC,MAAAA,IAAI,EAAEiB,aAHM;AAIZhB,MAAAA,QAAQ,EAAE,CAAE;AAAEC,QAAAA;AAAF,OAAF,KAAiB;AAC1B,cAAMC,IAAI,GAAG;AACZY,UAAAA,IAAI,EAAE;AADM,SAAb;AAGA,cAAMV,SAAS,GAAG,uBAAc,iBAAd,EAAiCF,IAAjC,CAAlB;;AACA,YAAKf,YAAL,EAAoB;AACnBlB,UAAAA,OAAO,CAACoC,IAAR,CAAcH,IAAd;AACA,SAFD,MAEO;AACNI,UAAAA,QAAQ,CAACjB,QAAT,GAAoBe,SAApB;AACA;;AACDH,QAAAA,KAAK;AACL;AAfW,KAAb;AAiBA,WAAOW,MAAP;AACA,GA5FgB,EA4Fd,CAAE3C,OAAF,EAAWkB,YAAX,CA5Fc,CAAjB;AA8FA,SAAO;AACNJ,IAAAA,QADM;AAENV,IAAAA,SAAS,EAAE;AAFL,GAAP;AAIA;;AAEM,SAAS4C,+BAAT,GAA2C;AACjD,kCAAkB;AACjBxB,IAAAA,IAAI,EAAE,+BADW;AAEjByB,IAAAA,IAAI,EAAEX;AAFW,GAAlB;AAIA,kCAAkB;AACjBd,IAAAA,IAAI,EAAE,+BADW;AAEjByB,IAAAA,IAAI,EAAEV;AAFW,GAAlB;AAIA,kCAAkB;AACjBf,IAAAA,IAAI,EAAE,mCADW;AAEjByB,IAAAA,IAAI,EAAET;AAFW,GAAlB;AAIA,kCAAkB;AACjBhB,IAAAA,IAAI,EAAE,wCADW;AAEjByB,IAAAA,IAAI,EAAER;AAFW,GAAlB;AAIA,kCAAkB;AACjBjB,IAAAA,IAAI,EAAE,iCADW;AAEjByB,IAAAA,IAAI,EAAEP,oCAFW;AAGjBQ,IAAAA,OAAO,EAAE;AAHQ,GAAlB;AAKA","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 {\n\tpost,\n\tpage,\n\tlayout,\n\tsymbolFilled,\n\tstyles,\n\tnavigation,\n\tsymbol,\n} 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\t\tstatus: [\n\t\t\t\t\t\t\t\t'publish',\n\t\t\t\t\t\t\t\t'future',\n\t\t\t\t\t\t\t\t'draft',\n\t\t\t\t\t\t\t\t'pending',\n\t\t\t\t\t\t\t\t'private',\n\t\t\t\t\t\t\t],\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};\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\nfunction useSiteEditorBasicNavigationCommands() {\n\tconst history = useHistory();\n\tconst isSiteEditor = getPath( window.location.href )?.includes(\n\t\t'site-editor.php'\n\t);\n\tconst commands = useMemo( () => {\n\t\tconst result = [];\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-navigation',\n\t\t\tlabel: __( 'Open navigation' ),\n\t\t\ticon: navigation,\n\t\t\tcallback: ( { close } ) => {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/navigation',\n\t\t\t\t};\n\t\t\t\tconst targetUrl = addQueryArgs( 'site-editor.php', args );\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t},\n\t\t} );\n\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-pages',\n\t\t\tlabel: __( 'Open pages' ),\n\t\t\ticon: page,\n\t\t\tcallback: ( { close } ) => {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/page',\n\t\t\t\t};\n\t\t\t\tconst targetUrl = addQueryArgs( 'site-editor.php', args );\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t},\n\t\t} );\n\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-style-variations',\n\t\t\tlabel: __( 'Open style variations' ),\n\t\t\ticon: styles,\n\t\t\tcallback: ( { close } ) => {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/wp_global_styles',\n\t\t\t\t};\n\t\t\t\tconst targetUrl = addQueryArgs( 'site-editor.php', args );\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t},\n\t\t} );\n\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-templates',\n\t\t\tlabel: __( 'Open templates' ),\n\t\t\ticon: layout,\n\t\t\tcallback: ( { close } ) => {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/wp_template',\n\t\t\t\t};\n\t\t\t\tconst targetUrl = addQueryArgs( 'site-editor.php', args );\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t},\n\t\t} );\n\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-template-parts',\n\t\t\tlabel: __( 'Open patterns' ),\n\t\t\ticon: symbol,\n\t\t\tcallback: ( { close } ) => {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/patterns',\n\t\t\t\t};\n\t\t\t\tconst targetUrl = addQueryArgs( 'site-editor.php', args );\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t},\n\t\t} );\n\t\treturn result;\n\t}, [ history, isSiteEditor ] );\n\n\treturn {\n\t\tcommands,\n\t\tisLoading: false,\n\t};\n}\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\tuseCommandLoader( {\n\t\tname: 'core/edit-site/basic-navigation',\n\t\thook: useSiteEditorBasicNavigationCommands,\n\t\tcontext: 'site-editor',\n\t} );\n}\n"]}
|
|
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","status","hasFinishedResolution","commands","slice","map","record","isSiteEditor","window","location","href","extraArgs","canvas","name","id","searchLabel","title","rendered","label","icon","callback","close","args","postId","targetUrl","push","document","usePageNavigationCommandLoader","usePostNavigationCommandLoader","useTemplateNavigationCommandLoader","useTemplatePartNavigationCommandLoader","useSiteEditorBasicNavigationCommands","isSiteEditorAccessible","result","navigation","path","styles","useSiteEditorNavigationCommands","hook","context"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAQA;;AACA;;AAKA;;AACA;;AAvBA;AACA;AACA;;AAiBA;AACA;AACA;AAIA,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,CAAnC;AACA,UAAMC,KAAK,G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AS4C,+BAAT,GAA2C;AACjD,kCAAkB;AACjBxB,IAAAA,IAAI,EAAE,+BADW;AAEjByB,IAAAA,IAAI,EAAEX;AAFW,GAAlB;AAIA,kCAAkB;AACjBd,IAAAA,IAAI,EAAE,+BADW;AAEjByB,IAAAA,IAAI,EAAEV;AAFW,GAAlB;AAIA,kCAAkB;AACjBf,IAAAA,IAAI,EAAE,mCADW;AAEjByB,IAAAA,IAAI,EAAET;AAFW,GAAlB;AAIA,kCAAkB;AACjBhB,IAAAA,IAAI,EAAE,wCADW;AAEjByB,IAAAA,IAAI,EAAER;AAFW,GAAlB;AAIA,kCAAkB;AACjBjB,IAAAA,IAAI,EAAE,iCADW;AAEjByB,IAAAA,IAAI,EAAEP,oCAFW;AAGjBQ,IAAAA,OAAO,EAAE;AAHQ,GAAlB;AAKA","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 {\n\tpost,\n\tpage,\n\tlayout,\n\tsymbolFilled,\n\tstyles,\n\tnavigation,\n} from '@wordpress/icons';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { getQueryArg, addQueryArgs, getPath } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { useIsSiteEditorAccessible } from './hooks';\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\t\tstatus: [\n\t\t\t\t\t\t\t\t'publish',\n\t\t\t\t\t\t\t\t'future',\n\t\t\t\t\t\t\t\t'draft',\n\t\t\t\t\t\t\t\t'pending',\n\t\t\t\t\t\t\t\t'private',\n\t\t\t\t\t\t\t],\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};\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\nfunction useSiteEditorBasicNavigationCommands() {\n\tconst history = useHistory();\n\tconst isSiteEditor = getPath( window.location.href )?.includes(\n\t\t'site-editor.php'\n\t);\n\tconst isSiteEditorAccessible = useIsSiteEditorAccessible();\n\tconst commands = useMemo( () => {\n\t\tconst result = [];\n\n\t\tif ( ! isSiteEditorAccessible ) {\n\t\t\treturn result;\n\t\t}\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-navigation',\n\t\t\tlabel: __( 'Open navigation' ),\n\t\t\ticon: navigation,\n\t\t\tcallback: ( { close } ) => {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/navigation',\n\t\t\t\t};\n\t\t\t\tconst targetUrl = addQueryArgs( 'site-editor.php', args );\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t},\n\t\t} );\n\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-pages',\n\t\t\tlabel: __( 'Open pages' ),\n\t\t\ticon: page,\n\t\t\tcallback: ( { close } ) => {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/page',\n\t\t\t\t};\n\t\t\t\tconst targetUrl = addQueryArgs( 'site-editor.php', args );\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t},\n\t\t} );\n\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-style-variations',\n\t\t\tlabel: __( 'Open style variations' ),\n\t\t\ticon: styles,\n\t\t\tcallback: ( { close } ) => {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/wp_global_styles',\n\t\t\t\t};\n\t\t\t\tconst targetUrl = addQueryArgs( 'site-editor.php', args );\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t},\n\t\t} );\n\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-templates',\n\t\t\tlabel: __( 'Open templates' ),\n\t\t\ticon: layout,\n\t\t\tcallback: ( { close } ) => {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/wp_template',\n\t\t\t\t};\n\t\t\t\tconst targetUrl = addQueryArgs( 'site-editor.php', args );\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t},\n\t\t} );\n\n\t\treturn result;\n\t}, [ history, isSiteEditor, isSiteEditorAccessible ] );\n\n\treturn {\n\t\tcommands,\n\t\tisLoading: false,\n\t};\n}\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\tuseCommandLoader( {\n\t\tname: 'core/edit-site/basic-navigation',\n\t\thook: useSiteEditorBasicNavigationCommands,\n\t\tcontext: 'site-editor',\n\t} );\n}\n"]}
|
|
@@ -3,8 +3,22 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { useCommand } from '@wordpress/commands';
|
|
5
5
|
import { __ } from '@wordpress/i18n';
|
|
6
|
-
import { external, plus } from '@wordpress/icons';
|
|
6
|
+
import { external, plus, symbol } from '@wordpress/icons';
|
|
7
|
+
import { addQueryArgs, getPath } from '@wordpress/url';
|
|
8
|
+
import { privateApis as routerPrivateApis } from '@wordpress/router';
|
|
9
|
+
/**
|
|
10
|
+
* Internal dependencies
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { useIsSiteEditorAccessible } from './hooks';
|
|
14
|
+
import { unlock } from './lock-unlock';
|
|
15
|
+
const {
|
|
16
|
+
useHistory
|
|
17
|
+
} = unlock(routerPrivateApis);
|
|
7
18
|
export function useAdminNavigationCommands() {
|
|
19
|
+
const history = useHistory();
|
|
20
|
+
const isSiteEditorAccessible = useIsSiteEditorAccessible();
|
|
21
|
+
const isSiteEditor = getPath(window.location.href)?.includes('site-editor.php');
|
|
8
22
|
useCommand({
|
|
9
23
|
name: 'core/add-new-post',
|
|
10
24
|
label: __('Add new post'),
|
|
@@ -23,11 +37,27 @@ export function useAdminNavigationCommands() {
|
|
|
23
37
|
});
|
|
24
38
|
useCommand({
|
|
25
39
|
name: 'core/manage-reusable-blocks',
|
|
26
|
-
label: __('
|
|
27
|
-
callback: (
|
|
28
|
-
|
|
40
|
+
label: __('Open patterns'),
|
|
41
|
+
callback: ({
|
|
42
|
+
close
|
|
43
|
+
}) => {
|
|
44
|
+
if (!isSiteEditorAccessible) {
|
|
45
|
+
document.location.href = 'edit.php?post_type=wp_block';
|
|
46
|
+
} else {
|
|
47
|
+
const args = {
|
|
48
|
+
path: '/patterns'
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
if (isSiteEditor) {
|
|
52
|
+
history.push(args);
|
|
53
|
+
} else {
|
|
54
|
+
document.location = addQueryArgs('site-editor.php', args);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
close();
|
|
58
|
+
}
|
|
29
59
|
},
|
|
30
|
-
icon: external
|
|
60
|
+
icon: isSiteEditor ? symbol : external
|
|
31
61
|
});
|
|
32
62
|
}
|
|
33
63
|
//# sourceMappingURL=admin-navigation-commands.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-commands/src/admin-navigation-commands.js"],"names":["useCommand","__","external","plus","useAdminNavigationCommands","name","label","icon","callback","document","
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-commands/src/admin-navigation-commands.js"],"names":["useCommand","__","external","plus","symbol","addQueryArgs","getPath","privateApis","routerPrivateApis","useIsSiteEditorAccessible","unlock","useHistory","useAdminNavigationCommands","history","isSiteEditorAccessible","isSiteEditor","window","location","href","includes","name","label","icon","callback","document","close","args","path","push"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,UAAT,QAA2B,qBAA3B;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,QAAT,EAAmBC,IAAnB,EAAyBC,MAAzB,QAAuC,kBAAvC;AACA,SAASC,YAAT,EAAuBC,OAAvB,QAAsC,gBAAtC;AACA,SAASC,WAAW,IAAIC,iBAAxB,QAAiD,mBAAjD;AAEA;AACA;AACA;;AACA,SAASC,yBAAT,QAA0C,SAA1C;AACA,SAASC,MAAT,QAA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AAoB;AACnBF,UAAAA,OAAO,CAACe,IAAR,CAAcF,IAAd;AACA,SAFD,MAEO;AACNF,UAAAA,QAAQ,CAACP,QAAT,GAAoBZ,YAAY,CAAE,iBAAF,EAAqBqB,IAArB,CAAhC;AACA;;AACDD,QAAAA,KAAK;AACL;AACD,KAjBU;AAkBXH,IAAAA,IAAI,EAAEP,YAAY,GAAGX,MAAH,GAAYF;AAlBnB,GAAF,CAAV;AAoBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCommand } from '@wordpress/commands';\nimport { __ } from '@wordpress/i18n';\nimport { external, plus, symbol } from '@wordpress/icons';\nimport { addQueryArgs, getPath } from '@wordpress/url';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\n\n/**\n * Internal dependencies\n */\nimport { useIsSiteEditorAccessible } from './hooks';\nimport { unlock } from './lock-unlock';\n\nconst { useHistory } = unlock( routerPrivateApis );\n\nexport function useAdminNavigationCommands() {\n\tconst history = useHistory();\n\tconst isSiteEditorAccessible = useIsSiteEditorAccessible();\n\n\tconst isSiteEditor = getPath( window.location.href )?.includes(\n\t\t'site-editor.php'\n\t);\n\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\tuseCommand( {\n\t\tname: 'core/manage-reusable-blocks',\n\t\tlabel: __( 'Open patterns' ),\n\t\tcallback: ( { close } ) => {\n\t\t\tif ( ! isSiteEditorAccessible ) {\n\t\t\t\tdocument.location.href = 'edit.php?post_type=wp_block';\n\t\t\t} else {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/patterns',\n\t\t\t\t};\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = addQueryArgs( 'site-editor.php', args );\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t}\n\t\t},\n\t\ticon: isSiteEditor ? symbol : external,\n\t} );\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
5
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
6
|
+
import { useSelect } from '@wordpress/data';
|
|
7
|
+
export function useIsSiteEditorAccessible() {
|
|
8
|
+
return useSelect(select => select(blockEditorStore).getSettings().__unstableIsBlockBasedTheme && select(coreStore).canUser('read', 'templates'), []);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-commands/src/hooks.js"],"names":["store","blockEditorStore","coreStore","useSelect","useIsSiteEditorAccessible","select","getSettings","__unstableIsBlockBasedTheme","canUser"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,KAAK,IAAIC,gBAAlB,QAA0C,yBAA1C;AACA,SAASD,KAAK,IAAIE,SAAlB,QAAmC,sBAAnC;AACA,SAASC,SAAT,QAA0B,iBAA1B;AAEA,OAAO,SAASC,yBAAT,GAAqC;AAC3C,SAAOD,SAAS,CACbE,MAAF,IACCA,MAAM,CAAEJ,gBAAF,CAAN,CAA2BK,WAA3B,GACEC,2BADF,IAEAF,MAAM,CAAEH,SAAF,CAAN,CAAoBM,OAApB,CAA6B,MAA7B,EAAqC,WAArC,CAJc,EAKf,EALe,CAAhB;AAOA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useSelect } from '@wordpress/data';\n\nexport function useIsSiteEditorAccessible() {\n\treturn useSelect(\n\t\t( select ) =>\n\t\t\tselect( blockEditorStore ).getSettings()\n\t\t\t\t.__unstableIsBlockBasedTheme &&\n\t\t\tselect( coreStore ).canUser( 'read', 'templates' ),\n\t\t[]\n\t);\n}\n"]}
|
|
@@ -6,13 +6,14 @@ import { __ } from '@wordpress/i18n';
|
|
|
6
6
|
import { useMemo } from '@wordpress/element';
|
|
7
7
|
import { useSelect } from '@wordpress/data';
|
|
8
8
|
import { store as coreStore } from '@wordpress/core-data';
|
|
9
|
-
import { post, page, layout, symbolFilled, styles, navigation
|
|
9
|
+
import { post, page, layout, symbolFilled, styles, navigation } from '@wordpress/icons';
|
|
10
10
|
import { privateApis as routerPrivateApis } from '@wordpress/router';
|
|
11
11
|
import { getQueryArg, addQueryArgs, getPath } from '@wordpress/url';
|
|
12
12
|
/**
|
|
13
13
|
* Internal dependencies
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
+
import { useIsSiteEditorAccessible } from './hooks';
|
|
16
17
|
import { unlock } from './lock-unlock';
|
|
17
18
|
const {
|
|
18
19
|
useHistory
|
|
@@ -95,8 +96,14 @@ const useTemplatePartNavigationCommandLoader = getNavigationCommandLoaderPerPost
|
|
|
95
96
|
function useSiteEditorBasicNavigationCommands() {
|
|
96
97
|
const history = useHistory();
|
|
97
98
|
const isSiteEditor = getPath(window.location.href)?.includes('site-editor.php');
|
|
99
|
+
const isSiteEditorAccessible = useIsSiteEditorAccessible();
|
|
98
100
|
const commands = useMemo(() => {
|
|
99
101
|
const result = [];
|
|
102
|
+
|
|
103
|
+
if (!isSiteEditorAccessible) {
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
|
|
100
107
|
result.push({
|
|
101
108
|
name: 'core/edit-site/open-navigation',
|
|
102
109
|
label: __('Open navigation'),
|
|
@@ -181,29 +188,8 @@ function useSiteEditorBasicNavigationCommands() {
|
|
|
181
188
|
close();
|
|
182
189
|
}
|
|
183
190
|
});
|
|
184
|
-
result.push({
|
|
185
|
-
name: 'core/edit-site/open-template-parts',
|
|
186
|
-
label: __('Open patterns'),
|
|
187
|
-
icon: symbol,
|
|
188
|
-
callback: ({
|
|
189
|
-
close
|
|
190
|
-
}) => {
|
|
191
|
-
const args = {
|
|
192
|
-
path: '/patterns'
|
|
193
|
-
};
|
|
194
|
-
const targetUrl = addQueryArgs('site-editor.php', args);
|
|
195
|
-
|
|
196
|
-
if (isSiteEditor) {
|
|
197
|
-
history.push(args);
|
|
198
|
-
} else {
|
|
199
|
-
document.location = targetUrl;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
close();
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
191
|
return result;
|
|
206
|
-
}, [history, isSiteEditor]);
|
|
192
|
+
}, [history, isSiteEditor, isSiteEditorAccessible]);
|
|
207
193
|
return {
|
|
208
194
|
commands,
|
|
209
195
|
isLoading: false
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-commands/src/site-editor-navigation-commands.js"],"names":["useCommandLoader","__","useMemo","useSelect","store","coreStore","post","page","layout","symbolFilled","styles","navigation","symbol","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","status","hasFinishedResolution","commands","slice","map","record","isSiteEditor","window","location","href","extraArgs","canvas","name","id","searchLabel","title","rendered","label","icon","callback","close","args","postId","targetUrl","push","document","usePageNavigationCommandLoader","usePostNavigationCommandLoader","useTemplateNavigationCommandLoader","useTemplatePartNavigationCommandLoader","useSiteEditorBasicNavigationCommands","result","path","useSiteEditorNavigationCommands","hook","context"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,gBAAT,QAAiC,qBAAjC;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,OAAT,QAAwB,oBAAxB;AACA,SAASC,SAAT,QAA0B,iBAA1B;AAC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I,UAAAA,QAAQ,CAACjB,QAAT,GAAoBe,SAApB;AACA;;AACDH,QAAAA,KAAK;AACL;AAfW,KAAb;AAiBA,WAAOW,MAAP;AACA,GA5FuB,EA4FrB,CAAE1C,OAAF,EAAWiB,YAAX,CA5FqB,CAAxB;AA8FA,SAAO;AACNJ,IAAAA,QADM;AAENT,IAAAA,SAAS,EAAE;AAFL,GAAP;AAIA;;AAED,OAAO,SAASwC,+BAAT,GAA2C;AACjDvE,EAAAA,gBAAgB,CAAE;AACjBkD,IAAAA,IAAI,EAAE,+BADW;AAEjBsB,IAAAA,IAAI,EAAER;AAFW,GAAF,CAAhB;AAIAhE,EAAAA,gBAAgB,CAAE;AACjBkD,IAAAA,IAAI,EAAE,+BADW;AAEjBsB,IAAAA,IAAI,EAAEP;AAFW,GAAF,CAAhB;AAIAjE,EAAAA,gBAAgB,CAAE;AACjBkD,IAAAA,IAAI,EAAE,mCADW;AAEjBsB,IAAAA,IAAI,EAAEN;AAFW,GAAF,CAAhB;AAIAlE,EAAAA,gBAAgB,CAAE;AACjBkD,IAAAA,IAAI,EAAE,wCADW;AAEjBsB,IAAAA,IAAI,EAAEL;AAFW,GAAF,CAAhB;AAIAnE,EAAAA,gBAAgB,CAAE;AACjBkD,IAAAA,IAAI,EAAE,iCADW;AAEjBsB,IAAAA,IAAI,EAAEJ,oCAFW;AAGjBK,IAAAA,OAAO,EAAE;AAHQ,GAAF,CAAhB;AAKA","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 {\n\tpost,\n\tpage,\n\tlayout,\n\tsymbolFilled,\n\tstyles,\n\tnavigation,\n\tsymbol,\n} 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\t\tstatus: [\n\t\t\t\t\t\t\t\t'publish',\n\t\t\t\t\t\t\t\t'future',\n\t\t\t\t\t\t\t\t'draft',\n\t\t\t\t\t\t\t\t'pending',\n\t\t\t\t\t\t\t\t'private',\n\t\t\t\t\t\t\t],\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};\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\nfunction useSiteEditorBasicNavigationCommands() {\n\tconst history = useHistory();\n\tconst isSiteEditor = getPath( window.location.href )?.includes(\n\t\t'site-editor.php'\n\t);\n\tconst commands = useMemo( () => {\n\t\tconst result = [];\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-navigation',\n\t\t\tlabel: __( 'Open navigation' ),\n\t\t\ticon: navigation,\n\t\t\tcallback: ( { close } ) => {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/navigation',\n\t\t\t\t};\n\t\t\t\tconst targetUrl = addQueryArgs( 'site-editor.php', args );\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t},\n\t\t} );\n\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-pages',\n\t\t\tlabel: __( 'Open pages' ),\n\t\t\ticon: page,\n\t\t\tcallback: ( { close } ) => {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/page',\n\t\t\t\t};\n\t\t\t\tconst targetUrl = addQueryArgs( 'site-editor.php', args );\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t},\n\t\t} );\n\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-style-variations',\n\t\t\tlabel: __( 'Open style variations' ),\n\t\t\ticon: styles,\n\t\t\tcallback: ( { close } ) => {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/wp_global_styles',\n\t\t\t\t};\n\t\t\t\tconst targetUrl = addQueryArgs( 'site-editor.php', args );\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t},\n\t\t} );\n\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-templates',\n\t\t\tlabel: __( 'Open templates' ),\n\t\t\ticon: layout,\n\t\t\tcallback: ( { close } ) => {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/wp_template',\n\t\t\t\t};\n\t\t\t\tconst targetUrl = addQueryArgs( 'site-editor.php', args );\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t},\n\t\t} );\n\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-template-parts',\n\t\t\tlabel: __( 'Open patterns' ),\n\t\t\ticon: symbol,\n\t\t\tcallback: ( { close } ) => {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/patterns',\n\t\t\t\t};\n\t\t\t\tconst targetUrl = addQueryArgs( 'site-editor.php', args );\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t},\n\t\t} );\n\t\treturn result;\n\t}, [ history, isSiteEditor ] );\n\n\treturn {\n\t\tcommands,\n\t\tisLoading: false,\n\t};\n}\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\tuseCommandLoader( {\n\t\tname: 'core/edit-site/basic-navigation',\n\t\thook: useSiteEditorBasicNavigationCommands,\n\t\tcontext: 'site-editor',\n\t} );\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-commands/src/site-editor-navigation-commands.js"],"names":["useCommandLoader","__","useMemo","useSelect","store","coreStore","post","page","layout","symbolFilled","styles","navigation","privateApis","routerPrivateApis","getQueryArg","addQueryArgs","getPath","useIsSiteEditorAccessible","unlock","useHistory","icons","wp_template","wp_template_part","getNavigationCommandLoaderPerPostType","postType","useNavigationCommandLoader","search","history","supportsSearch","includes","records","isLoading","select","getEntityRecords","query","undefined","per_page","orderby","status","hasFinishedResolution","commands","slice","map","record","isSiteEditor","window","location","href","extraArgs","canvas","name","id","searchLabel","title","rendered","label","icon","callback","close","args","postId","targetUrl","push","document","usePageNavigationCommandLoader","usePostNavigationCommandLoader","useTemplateNavigationCommandLoader","useTemplatePartNavigationCommandLoader","useSiteEditorBasicNavigationCommands","isSiteEditorAccessible","result","path","useSiteEditorNavigationCommands","hook","context"],"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,SACCC,IADD,EAECC,IAFD,EAGCC,MAHD,EAICC,YAJD,EAKCC,MALD,EAMCC,UAND,QAOO,kBAPP;AAQA,SAASC,WAAW,IAAIC,iBAAxB,QAAiD,mBAAjD;AACA,SAASC,WAAT,EAAsBC,YAAtB,EAAoCC,OAApC,QAAmD,gBAAnD;AAEA;AACA;AACA;;AACA,SAASC,yBAAT,QAA0C,SAA1C;AACA,SAASC,MAAT,QAAuB,eAAvB;AAEA,MAAM;AAAEC,EAAAA;AAAF,IAAiBD,MAAM,CAAEL,iBAAF,CAA7B;AAEA,MAAMO,KAAK,GAAG;AACbd,EAAAA,IADa;AAEbC,EAAAA,IAFa;AAGbc,EAAAA,WAAW,EAAEb,MAHA;AAIbc,EAAAA,gBAAgB,EAAEb;AAJL,CAAd;;AAOA,MAAMc,qCAAqC,GAAKC,QAAF,IAC7C,SAASC,0BAAT,CAAqC;AAAEC,EAAAA;AAAF,CAArC,EAAkD;AACjD,QAAMC,OAAO,GAAGR,UAAU,EAA1B;AACA,QAAMS,cAAc,GAAG,CAAE,CAAE,aAAF,EAAiB,kBAAjB,E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f,YAAL,EAAoB;AACnBjB,UAAAA,OAAO,CAACmC,IAAR,CAAcH,IAAd;AACA,SAFD,MAEO;AACNI,UAAAA,QAAQ,CAACjB,QAAT,GAAoBe,SAApB;AACA;;AACDH,QAAAA,KAAK;AACL;AAfW,KAAb;AAkBA,WAAOY,MAAP;AACA,GA/EuB,EA+ErB,CAAE3C,OAAF,EAAWiB,YAAX,EAAyByB,sBAAzB,CA/EqB,CAAxB;AAiFA,SAAO;AACN7B,IAAAA,QADM;AAENT,IAAAA,SAAS,EAAE;AAFL,GAAP;AAIA;;AAED,OAAO,SAASyC,+BAAT,GAA2C;AACjDxE,EAAAA,gBAAgB,CAAE;AACjBkD,IAAAA,IAAI,EAAE,+BADW;AAEjBuB,IAAAA,IAAI,EAAET;AAFW,GAAF,CAAhB;AAIAhE,EAAAA,gBAAgB,CAAE;AACjBkD,IAAAA,IAAI,EAAE,+BADW;AAEjBuB,IAAAA,IAAI,EAAER;AAFW,GAAF,CAAhB;AAIAjE,EAAAA,gBAAgB,CAAE;AACjBkD,IAAAA,IAAI,EAAE,mCADW;AAEjBuB,IAAAA,IAAI,EAAEP;AAFW,GAAF,CAAhB;AAIAlE,EAAAA,gBAAgB,CAAE;AACjBkD,IAAAA,IAAI,EAAE,wCADW;AAEjBuB,IAAAA,IAAI,EAAEN;AAFW,GAAF,CAAhB;AAIAnE,EAAAA,gBAAgB,CAAE;AACjBkD,IAAAA,IAAI,EAAE,iCADW;AAEjBuB,IAAAA,IAAI,EAAEL,oCAFW;AAGjBM,IAAAA,OAAO,EAAE;AAHQ,GAAF,CAAhB;AAKA","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 {\n\tpost,\n\tpage,\n\tlayout,\n\tsymbolFilled,\n\tstyles,\n\tnavigation,\n} from '@wordpress/icons';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { getQueryArg, addQueryArgs, getPath } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { useIsSiteEditorAccessible } from './hooks';\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\t\tstatus: [\n\t\t\t\t\t\t\t\t'publish',\n\t\t\t\t\t\t\t\t'future',\n\t\t\t\t\t\t\t\t'draft',\n\t\t\t\t\t\t\t\t'pending',\n\t\t\t\t\t\t\t\t'private',\n\t\t\t\t\t\t\t],\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};\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\nfunction useSiteEditorBasicNavigationCommands() {\n\tconst history = useHistory();\n\tconst isSiteEditor = getPath( window.location.href )?.includes(\n\t\t'site-editor.php'\n\t);\n\tconst isSiteEditorAccessible = useIsSiteEditorAccessible();\n\tconst commands = useMemo( () => {\n\t\tconst result = [];\n\n\t\tif ( ! isSiteEditorAccessible ) {\n\t\t\treturn result;\n\t\t}\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-navigation',\n\t\t\tlabel: __( 'Open navigation' ),\n\t\t\ticon: navigation,\n\t\t\tcallback: ( { close } ) => {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/navigation',\n\t\t\t\t};\n\t\t\t\tconst targetUrl = addQueryArgs( 'site-editor.php', args );\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t},\n\t\t} );\n\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-pages',\n\t\t\tlabel: __( 'Open pages' ),\n\t\t\ticon: page,\n\t\t\tcallback: ( { close } ) => {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/page',\n\t\t\t\t};\n\t\t\t\tconst targetUrl = addQueryArgs( 'site-editor.php', args );\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t},\n\t\t} );\n\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-style-variations',\n\t\t\tlabel: __( 'Open style variations' ),\n\t\t\ticon: styles,\n\t\t\tcallback: ( { close } ) => {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/wp_global_styles',\n\t\t\t\t};\n\t\t\t\tconst targetUrl = addQueryArgs( 'site-editor.php', args );\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t},\n\t\t} );\n\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-templates',\n\t\t\tlabel: __( 'Open templates' ),\n\t\t\ticon: layout,\n\t\t\tcallback: ( { close } ) => {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/wp_template',\n\t\t\t\t};\n\t\t\t\tconst targetUrl = addQueryArgs( 'site-editor.php', args );\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t},\n\t\t} );\n\n\t\treturn result;\n\t}, [ history, isSiteEditor, isSiteEditorAccessible ] );\n\n\treturn {\n\t\tcommands,\n\t\tisLoading: false,\n\t};\n}\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\tuseCommandLoader( {\n\t\tname: 'core/edit-site/basic-navigation',\n\t\thook: useSiteEditorBasicNavigationCommands,\n\t\tcontext: 'site-editor',\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.8.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,16 @@
|
|
|
27
27
|
"sideEffects": false,
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@babel/runtime": "^7.16.0",
|
|
30
|
-
"@wordpress/
|
|
31
|
-
"@wordpress/
|
|
32
|
-
"@wordpress/data": "^
|
|
33
|
-
"@wordpress/
|
|
34
|
-
"@wordpress/
|
|
35
|
-
"@wordpress/
|
|
36
|
-
"@wordpress/
|
|
37
|
-
"@wordpress/
|
|
38
|
-
"@wordpress/
|
|
30
|
+
"@wordpress/block-editor": "^12.7.0",
|
|
31
|
+
"@wordpress/commands": "^0.10.0",
|
|
32
|
+
"@wordpress/core-data": "^6.16.0",
|
|
33
|
+
"@wordpress/data": "^9.9.0",
|
|
34
|
+
"@wordpress/element": "^5.16.0",
|
|
35
|
+
"@wordpress/i18n": "^4.39.0",
|
|
36
|
+
"@wordpress/icons": "^9.30.0",
|
|
37
|
+
"@wordpress/private-apis": "^0.21.0",
|
|
38
|
+
"@wordpress/router": "^0.8.0",
|
|
39
|
+
"@wordpress/url": "^3.40.0"
|
|
39
40
|
},
|
|
40
41
|
"peerDependencies": {
|
|
41
42
|
"react": "^18.0.0"
|
|
@@ -43,5 +44,5 @@
|
|
|
43
44
|
"publishConfig": {
|
|
44
45
|
"access": "public"
|
|
45
46
|
},
|
|
46
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "b898cf1dc8e70841d1647ea0994ac6278acc18a7"
|
|
47
48
|
}
|
|
@@ -3,9 +3,26 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { useCommand } from '@wordpress/commands';
|
|
5
5
|
import { __ } from '@wordpress/i18n';
|
|
6
|
-
import { external, plus } from '@wordpress/icons';
|
|
6
|
+
import { external, plus, symbol } from '@wordpress/icons';
|
|
7
|
+
import { addQueryArgs, getPath } from '@wordpress/url';
|
|
8
|
+
import { privateApis as routerPrivateApis } from '@wordpress/router';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Internal dependencies
|
|
12
|
+
*/
|
|
13
|
+
import { useIsSiteEditorAccessible } from './hooks';
|
|
14
|
+
import { unlock } from './lock-unlock';
|
|
15
|
+
|
|
16
|
+
const { useHistory } = unlock( routerPrivateApis );
|
|
7
17
|
|
|
8
18
|
export function useAdminNavigationCommands() {
|
|
19
|
+
const history = useHistory();
|
|
20
|
+
const isSiteEditorAccessible = useIsSiteEditorAccessible();
|
|
21
|
+
|
|
22
|
+
const isSiteEditor = getPath( window.location.href )?.includes(
|
|
23
|
+
'site-editor.php'
|
|
24
|
+
);
|
|
25
|
+
|
|
9
26
|
useCommand( {
|
|
10
27
|
name: 'core/add-new-post',
|
|
11
28
|
label: __( 'Add new post' ),
|
|
@@ -24,10 +41,22 @@ export function useAdminNavigationCommands() {
|
|
|
24
41
|
} );
|
|
25
42
|
useCommand( {
|
|
26
43
|
name: 'core/manage-reusable-blocks',
|
|
27
|
-
label: __( '
|
|
28
|
-
callback: () => {
|
|
29
|
-
|
|
44
|
+
label: __( 'Open patterns' ),
|
|
45
|
+
callback: ( { close } ) => {
|
|
46
|
+
if ( ! isSiteEditorAccessible ) {
|
|
47
|
+
document.location.href = 'edit.php?post_type=wp_block';
|
|
48
|
+
} else {
|
|
49
|
+
const args = {
|
|
50
|
+
path: '/patterns',
|
|
51
|
+
};
|
|
52
|
+
if ( isSiteEditor ) {
|
|
53
|
+
history.push( args );
|
|
54
|
+
} else {
|
|
55
|
+
document.location = addQueryArgs( 'site-editor.php', args );
|
|
56
|
+
}
|
|
57
|
+
close();
|
|
58
|
+
}
|
|
30
59
|
},
|
|
31
|
-
icon: external,
|
|
60
|
+
icon: isSiteEditor ? symbol : external,
|
|
32
61
|
} );
|
|
33
62
|
}
|
package/src/hooks.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
5
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
6
|
+
import { useSelect } from '@wordpress/data';
|
|
7
|
+
|
|
8
|
+
export function useIsSiteEditorAccessible() {
|
|
9
|
+
return useSelect(
|
|
10
|
+
( select ) =>
|
|
11
|
+
select( blockEditorStore ).getSettings()
|
|
12
|
+
.__unstableIsBlockBasedTheme &&
|
|
13
|
+
select( coreStore ).canUser( 'read', 'templates' ),
|
|
14
|
+
[]
|
|
15
|
+
);
|
|
16
|
+
}
|
|
@@ -13,7 +13,6 @@ import {
|
|
|
13
13
|
symbolFilled,
|
|
14
14
|
styles,
|
|
15
15
|
navigation,
|
|
16
|
-
symbol,
|
|
17
16
|
} from '@wordpress/icons';
|
|
18
17
|
import { privateApis as routerPrivateApis } from '@wordpress/router';
|
|
19
18
|
import { getQueryArg, addQueryArgs, getPath } from '@wordpress/url';
|
|
@@ -21,6 +20,7 @@ import { getQueryArg, addQueryArgs, getPath } from '@wordpress/url';
|
|
|
21
20
|
/**
|
|
22
21
|
* Internal dependencies
|
|
23
22
|
*/
|
|
23
|
+
import { useIsSiteEditorAccessible } from './hooks';
|
|
24
24
|
import { unlock } from './lock-unlock';
|
|
25
25
|
|
|
26
26
|
const { useHistory } = unlock( routerPrivateApis );
|
|
@@ -124,8 +124,13 @@ function useSiteEditorBasicNavigationCommands() {
|
|
|
124
124
|
const isSiteEditor = getPath( window.location.href )?.includes(
|
|
125
125
|
'site-editor.php'
|
|
126
126
|
);
|
|
127
|
+
const isSiteEditorAccessible = useIsSiteEditorAccessible();
|
|
127
128
|
const commands = useMemo( () => {
|
|
128
129
|
const result = [];
|
|
130
|
+
|
|
131
|
+
if ( ! isSiteEditorAccessible ) {
|
|
132
|
+
return result;
|
|
133
|
+
}
|
|
129
134
|
result.push( {
|
|
130
135
|
name: 'core/edit-site/open-navigation',
|
|
131
136
|
label: __( 'Open navigation' ),
|
|
@@ -198,25 +203,8 @@ function useSiteEditorBasicNavigationCommands() {
|
|
|
198
203
|
},
|
|
199
204
|
} );
|
|
200
205
|
|
|
201
|
-
result.push( {
|
|
202
|
-
name: 'core/edit-site/open-template-parts',
|
|
203
|
-
label: __( 'Open patterns' ),
|
|
204
|
-
icon: symbol,
|
|
205
|
-
callback: ( { close } ) => {
|
|
206
|
-
const args = {
|
|
207
|
-
path: '/patterns',
|
|
208
|
-
};
|
|
209
|
-
const targetUrl = addQueryArgs( 'site-editor.php', args );
|
|
210
|
-
if ( isSiteEditor ) {
|
|
211
|
-
history.push( args );
|
|
212
|
-
} else {
|
|
213
|
-
document.location = targetUrl;
|
|
214
|
-
}
|
|
215
|
-
close();
|
|
216
|
-
},
|
|
217
|
-
} );
|
|
218
206
|
return result;
|
|
219
|
-
}, [ history, isSiteEditor ] );
|
|
207
|
+
}, [ history, isSiteEditor, isSiteEditorAccessible ] );
|
|
220
208
|
|
|
221
209
|
return {
|
|
222
210
|
commands,
|