@wordpress/core-commands 0.8.0 → 0.9.1
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 +6 -15
- package/build/admin-navigation-commands.js.map +1 -1
- package/build/hooks.js +8 -8
- package/build/hooks.js.map +1 -1
- package/build/index.js +0 -1
- package/build/index.js.map +1 -1
- package/build/lock-unlock.js +1 -2
- package/build/lock-unlock.js.map +1 -1
- package/build/private-apis.js +1 -5
- package/build/private-apis.js.map +1 -1
- package/build/site-editor-navigation-commands.js +49 -42
- package/build/site-editor-navigation-commands.js.map +1 -1
- package/build/utils/order-entity-records-by-search.js +26 -0
- package/build/utils/order-entity-records-by-search.js.map +1 -0
- package/build-module/admin-navigation-commands.js +7 -8
- package/build-module/admin-navigation-commands.js.map +1 -1
- package/build-module/hooks.js +5 -3
- package/build-module/hooks.js.map +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/lock-unlock.js.map +1 -1
- package/build-module/private-apis.js +0 -2
- package/build-module/private-apis.js.map +1 -1
- package/build-module/site-editor-navigation-commands.js +51 -34
- package/build-module/site-editor-navigation-commands.js.map +1 -1
- package/build-module/utils/order-entity-records-by-search.js +20 -0
- package/build-module/utils/order-entity-records-by-search.js.map +1 -0
- package/package.json +14 -13
- package/src/admin-navigation-commands.js +6 -5
- package/src/hooks.js +9 -6
- package/src/site-editor-navigation-commands.js +51 -16
- package/src/utils/order-entity-records-by-search.js +25 -0
- package/src/utils/test/order-entity-records-by-search.js +83 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,21 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.useAdminNavigationCommands = useAdminNavigationCommands;
|
|
7
|
-
|
|
8
7
|
var _commands = require("@wordpress/commands");
|
|
9
|
-
|
|
10
8
|
var _i18n = require("@wordpress/i18n");
|
|
11
|
-
|
|
12
9
|
var _icons = require("@wordpress/icons");
|
|
13
|
-
|
|
14
10
|
var _url = require("@wordpress/url");
|
|
15
|
-
|
|
16
11
|
var _router = require("@wordpress/router");
|
|
17
|
-
|
|
18
12
|
var _hooks = require("./hooks");
|
|
19
|
-
|
|
20
13
|
var _lockUnlock = require("./lock-unlock");
|
|
21
|
-
|
|
22
14
|
/**
|
|
23
15
|
* WordPress dependencies
|
|
24
16
|
*/
|
|
@@ -26,13 +18,14 @@ var _lockUnlock = require("./lock-unlock");
|
|
|
26
18
|
/**
|
|
27
19
|
* Internal dependencies
|
|
28
20
|
*/
|
|
21
|
+
|
|
29
22
|
const {
|
|
30
23
|
useHistory
|
|
31
24
|
} = (0, _lockUnlock.unlock)(_router.privateApis);
|
|
32
|
-
|
|
33
25
|
function useAdminNavigationCommands() {
|
|
34
26
|
const history = useHistory();
|
|
35
|
-
const
|
|
27
|
+
const isTemplatesAccessible = (0, _hooks.useIsTemplatesAccessible)();
|
|
28
|
+
const isBlockBasedTheme = (0, _hooks.useIsBlockBasedTheme)();
|
|
36
29
|
const isSiteEditor = (0, _url.getPath)(window.location.href)?.includes('site-editor.php');
|
|
37
30
|
(0, _commands.useCommand)({
|
|
38
31
|
name: 'core/add-new-post',
|
|
@@ -56,20 +49,18 @@ function useAdminNavigationCommands() {
|
|
|
56
49
|
callback: ({
|
|
57
50
|
close
|
|
58
51
|
}) => {
|
|
59
|
-
if (
|
|
60
|
-
document.location.href = 'edit.php?post_type=wp_block';
|
|
61
|
-
} else {
|
|
52
|
+
if (isTemplatesAccessible && isBlockBasedTheme) {
|
|
62
53
|
const args = {
|
|
63
54
|
path: '/patterns'
|
|
64
55
|
};
|
|
65
|
-
|
|
66
56
|
if (isSiteEditor) {
|
|
67
57
|
history.push(args);
|
|
68
58
|
} else {
|
|
69
59
|
document.location = (0, _url.addQueryArgs)('site-editor.php', args);
|
|
70
60
|
}
|
|
71
|
-
|
|
72
61
|
close();
|
|
62
|
+
} else {
|
|
63
|
+
document.location.href = 'edit.php?post_type=wp_block';
|
|
73
64
|
}
|
|
74
65
|
},
|
|
75
66
|
icon: isSiteEditor ? _icons.symbol : _icons.external
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_commands","require","_i18n","_icons","_url","_router","_hooks","_lockUnlock","useHistory","unlock","routerPrivateApis","useAdminNavigationCommands","history","isTemplatesAccessible","useIsTemplatesAccessible","isBlockBasedTheme","useIsBlockBasedTheme","isSiteEditor","getPath","window","location","href","includes","useCommand","name","label","__","icon","plus","callback","document","close","args","path","push","addQueryArgs","symbol","external"],"sources":["@wordpress/core-commands/src/admin-navigation-commands.js"],"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 { useIsTemplatesAccessible, useIsBlockBasedTheme } from './hooks';\nimport { unlock } from './lock-unlock';\n\nconst { useHistory } = unlock( routerPrivateApis );\n\nexport function useAdminNavigationCommands() {\n\tconst history = useHistory();\n\tconst isTemplatesAccessible = useIsTemplatesAccessible();\n\tconst isBlockBasedTheme = useIsBlockBasedTheme();\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 ( isTemplatesAccessible && isBlockBasedTheme ) {\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} else {\n\t\t\t\tdocument.location.href = 'edit.php?post_type=wp_block';\n\t\t\t}\n\t\t},\n\t\ticon: isSiteEditor ? symbol : external,\n\t} );\n}\n"],"mappings":";;;;;;AAGA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,IAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AAKA,IAAAK,MAAA,GAAAL,OAAA;AACA,IAAAM,WAAA,GAAAN,OAAA;AAbA;AACA;AACA;;AAOA;AACA;AACA;;AAIA,MAAM;EAAEO;AAAW,CAAC,GAAG,IAAAC,kBAAM,EAAEC,mBAAkB,CAAC;AAE3C,SAASC,0BAA0BA,CAAA,EAAG;EAC5C,MAAMC,OAAO,GAAGJ,UAAU,CAAC,CAAC;EAC5B,MAAMK,qBAAqB,GAAG,IAAAC,+BAAwB,EAAC,CAAC;EACxD,MAAMC,iBAAiB,GAAG,IAAAC,2BAAoB,EAAC,CAAC;EAEhD,MAAMC,YAAY,GAAG,IAAAC,YAAO,EAAEC,MAAM,CAACC,QAAQ,CAACC,IAAK,CAAC,EAAEC,QAAQ,CAC7D,iBACD,CAAC;EAED,IAAAC,oBAAU,EAAE;IACXC,IAAI,EAAE,mBAAmB;IACzBC,KAAK,EAAE,IAAAC,QAAE,EAAE,cAAe,CAAC;IAC3BC,IAAI,EAAEC,WAAI;IACVC,QAAQ,EAAEA,CAAA,KAAM;MACfC,QAAQ,CAACV,QAAQ,CAACC,IAAI,GAAG,cAAc;IACxC;EACD,CAAE,CAAC;EACH,IAAAE,oBAAU,EAAE;IACXC,IAAI,EAAE,mBAAmB;IACzBC,KAAK,EAAE,IAAAC,QAAE,EAAE,cAAe,CAAC;IAC3BC,IAAI,EAAEC,WAAI;IACVC,QAAQ,EAAEA,CAAA,KAAM;MACfC,QAAQ,CAACV,QAAQ,CAACC,IAAI,GAAG,6BAA6B;IACvD;EACD,CAAE,CAAC;EACH,IAAAE,oBAAU,EAAE;IACXC,IAAI,EAAE,6BAA6B;IACnCC,KAAK,EAAE,IAAAC,QAAE,EAAE,eAAgB,CAAC;IAC5BG,QAAQ,EAAEA,CAAE;MAAEE;IAAM,CAAC,KAAM;MAC1B,IAAKlB,qBAAqB,IAAIE,iBAAiB,EAAG;QACjD,MAAMiB,IAAI,GAAG;UACZC,IAAI,EAAE;QACP,CAAC;QACD,IAAKhB,YAAY,EAAG;UACnBL,OAAO,CAACsB,IAAI,CAAEF,IAAK,CAAC;QACrB,CAAC,MAAM;UACNF,QAAQ,CAACV,QAAQ,GAAG,IAAAe,iBAAY,EAAE,iBAAiB,EAAEH,IAAK,CAAC;QAC5D;QACAD,KAAK,CAAC,CAAC;MACR,CAAC,MAAM;QACND,QAAQ,CAACV,QAAQ,CAACC,IAAI,GAAG,6BAA6B;MACvD;IACD,CAAC;IACDM,IAAI,EAAEV,YAAY,GAAGmB,aAAM,GAAGC;EAC/B,CAAE,CAAC;AACJ"}
|
package/build/hooks.js
CHANGED
|
@@ -3,18 +3,18 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
|
|
8
|
-
var _blockEditor = require("@wordpress/block-editor");
|
|
9
|
-
|
|
6
|
+
exports.useIsBlockBasedTheme = useIsBlockBasedTheme;
|
|
7
|
+
exports.useIsTemplatesAccessible = useIsTemplatesAccessible;
|
|
10
8
|
var _coreData = require("@wordpress/core-data");
|
|
11
|
-
|
|
12
9
|
var _data = require("@wordpress/data");
|
|
13
|
-
|
|
14
10
|
/**
|
|
15
11
|
* WordPress dependencies
|
|
16
12
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
|
|
14
|
+
function useIsTemplatesAccessible() {
|
|
15
|
+
return (0, _data.useSelect)(select => select(_coreData.store).canUser('read', 'templates'), []);
|
|
16
|
+
}
|
|
17
|
+
function useIsBlockBasedTheme() {
|
|
18
|
+
return (0, _data.useSelect)(select => select(_coreData.store).getCurrentTheme()?.is_block_theme, []);
|
|
19
19
|
}
|
|
20
20
|
//# sourceMappingURL=hooks.js.map
|
package/build/hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_coreData","require","_data","useIsTemplatesAccessible","useSelect","select","coreStore","canUser","useIsBlockBasedTheme","getCurrentTheme","is_block_theme"],"sources":["@wordpress/core-commands/src/hooks.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useSelect } from '@wordpress/data';\n\nexport function useIsTemplatesAccessible() {\n\treturn useSelect(\n\t\t( select ) => select( coreStore ).canUser( 'read', 'templates' ),\n\t\t[]\n\t);\n}\n\nexport function useIsBlockBasedTheme() {\n\treturn useSelect(\n\t\t( select ) => select( coreStore ).getCurrentTheme()?.is_block_theme,\n\t\t[]\n\t);\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAJA;AACA;AACA;;AAIO,SAASE,wBAAwBA,CAAA,EAAG;EAC1C,OAAO,IAAAC,eAAS,EACbC,MAAM,IAAMA,MAAM,CAAEC,eAAU,CAAC,CAACC,OAAO,CAAE,MAAM,EAAE,WAAY,CAAC,EAChE,EACD,CAAC;AACF;AAEO,SAASC,oBAAoBA,CAAA,EAAG;EACtC,OAAO,IAAAJ,eAAS,EACbC,MAAM,IAAMA,MAAM,CAAEC,eAAU,CAAC,CAACG,eAAe,CAAC,CAAC,EAAEC,cAAc,EACnE,EACD,CAAC;AACF"}
|
package/build/index.js
CHANGED
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-commands/src/index.js"],"
|
|
1
|
+
{"version":3,"names":["_privateApis","require"],"sources":["@wordpress/core-commands/src/index.js"],"sourcesContent":["export { privateApis } from './private-apis';\n"],"mappings":";;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA"}
|
package/build/lock-unlock.js
CHANGED
package/build/lock-unlock.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_privateApis","require","lock","unlock","__dangerousOptInToUnstableAPIsOnlyForCoreModules","exports"],"sources":["@wordpress/core-commands/src/lock-unlock.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';\n\nexport const { lock, unlock } =\n\t__dangerousOptInToUnstableAPIsOnlyForCoreModules(\n\t\t'I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.',\n\t\t'@wordpress/core-commands'\n\t);\n"],"mappings":";;;;;;AAGA,IAAAA,YAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGO,MAAM;EAAEC,IAAI;EAAEC;AAAO,CAAC,GAC5B,IAAAC,6DAAgD,EAC/C,8GAA8G,EAC9G,0BACD,CAAC;AAACC,OAAA,CAAAF,MAAA,GAAAA,MAAA;AAAAE,OAAA,CAAAH,IAAA,GAAAA,IAAA"}
|
package/build/private-apis.js
CHANGED
|
@@ -4,21 +4,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.privateApis = void 0;
|
|
7
|
-
|
|
8
7
|
var _adminNavigationCommands = require("./admin-navigation-commands");
|
|
9
|
-
|
|
10
8
|
var _siteEditorNavigationCommands = require("./site-editor-navigation-commands");
|
|
11
|
-
|
|
12
9
|
var _lockUnlock = require("./lock-unlock");
|
|
13
|
-
|
|
14
10
|
/**
|
|
15
11
|
* Internal dependencies
|
|
16
12
|
*/
|
|
13
|
+
|
|
17
14
|
function useCommands() {
|
|
18
15
|
(0, _adminNavigationCommands.useAdminNavigationCommands)();
|
|
19
16
|
(0, _siteEditorNavigationCommands.useSiteEditorNavigationCommands)();
|
|
20
17
|
}
|
|
21
|
-
|
|
22
18
|
const privateApis = {};
|
|
23
19
|
exports.privateApis = privateApis;
|
|
24
20
|
(0, _lockUnlock.lock)(privateApis, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_adminNavigationCommands","require","_siteEditorNavigationCommands","_lockUnlock","useCommands","useAdminNavigationCommands","useSiteEditorNavigationCommands","privateApis","exports","lock"],"sources":["@wordpress/core-commands/src/private-apis.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { useAdminNavigationCommands } from './admin-navigation-commands';\nimport { useSiteEditorNavigationCommands } from './site-editor-navigation-commands';\nimport { lock } from './lock-unlock';\n\nfunction useCommands() {\n\tuseAdminNavigationCommands();\n\tuseSiteEditorNavigationCommands();\n}\n\nexport const privateApis = {};\nlock( privateApis, {\n\tuseCommands,\n} );\n"],"mappings":";;;;;;AAGA,IAAAA,wBAAA,GAAAC,OAAA;AACA,IAAAC,6BAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AALA;AACA;AACA;;AAKA,SAASG,WAAWA,CAAA,EAAG;EACtB,IAAAC,mDAA0B,EAAC,CAAC;EAC5B,IAAAC,6DAA+B,EAAC,CAAC;AAClC;AAEO,MAAMC,WAAW,GAAG,CAAC,CAAC;AAACC,OAAA,CAAAD,WAAA,GAAAA,WAAA;AAC9B,IAAAE,gBAAI,EAAEF,WAAW,EAAE;EAClBH;AACD,CAAE,CAAC"}
|
|
@@ -4,27 +4,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.useSiteEditorNavigationCommands = useSiteEditorNavigationCommands;
|
|
7
|
-
|
|
8
7
|
var _commands = require("@wordpress/commands");
|
|
9
|
-
|
|
10
8
|
var _i18n = require("@wordpress/i18n");
|
|
11
|
-
|
|
12
9
|
var _element = require("@wordpress/element");
|
|
13
|
-
|
|
14
10
|
var _data = require("@wordpress/data");
|
|
15
|
-
|
|
16
11
|
var _coreData = require("@wordpress/core-data");
|
|
17
|
-
|
|
18
12
|
var _icons = require("@wordpress/icons");
|
|
19
|
-
|
|
20
13
|
var _router = require("@wordpress/router");
|
|
21
|
-
|
|
22
14
|
var _url = require("@wordpress/url");
|
|
23
|
-
|
|
24
15
|
var _hooks = require("./hooks");
|
|
25
|
-
|
|
26
16
|
var _lockUnlock = require("./lock-unlock");
|
|
27
|
-
|
|
17
|
+
var _orderEntityRecordsBySearch = require("./utils/order-entity-records-by-search");
|
|
28
18
|
/**
|
|
29
19
|
* WordPress dependencies
|
|
30
20
|
*/
|
|
@@ -32,6 +22,7 @@ var _lockUnlock = require("./lock-unlock");
|
|
|
32
22
|
/**
|
|
33
23
|
* Internal dependencies
|
|
34
24
|
*/
|
|
25
|
+
|
|
35
26
|
const {
|
|
36
27
|
useHistory
|
|
37
28
|
} = (0, _lockUnlock.unlock)(_router.privateApis);
|
|
@@ -41,7 +32,6 @@ const icons = {
|
|
|
41
32
|
wp_template: _icons.layout,
|
|
42
33
|
wp_template_part: _icons.symbolFilled
|
|
43
34
|
};
|
|
44
|
-
|
|
45
35
|
const getNavigationCommandLoaderPerPostType = postType => function useNavigationCommandLoader({
|
|
46
36
|
search
|
|
47
37
|
}) {
|
|
@@ -67,8 +57,20 @@ const getNavigationCommandLoaderPerPostType = postType => function useNavigation
|
|
|
67
57
|
isLoading: !select(_coreData.store).hasFinishedResolution('getEntityRecords', ['postType', postType, query])
|
|
68
58
|
};
|
|
69
59
|
}, [supportsSearch, search]);
|
|
60
|
+
|
|
61
|
+
/*
|
|
62
|
+
* wp_template and wp_template_part endpoints do not support per_page or orderby parameters.
|
|
63
|
+
* We need to sort the results based on the search query to avoid removing relevant
|
|
64
|
+
* records below using .slice().
|
|
65
|
+
*/
|
|
66
|
+
const orderedRecords = (0, _element.useMemo)(() => {
|
|
67
|
+
if (supportsSearch) {
|
|
68
|
+
return records !== null && records !== void 0 ? records : [];
|
|
69
|
+
}
|
|
70
|
+
return (0, _orderEntityRecordsBySearch.orderEntityRecordsBySearch)(records, search).slice(0, 10);
|
|
71
|
+
}, [supportsSearch, records, search]);
|
|
70
72
|
const commands = (0, _element.useMemo)(() => {
|
|
71
|
-
return
|
|
73
|
+
return orderedRecords.map(record => {
|
|
72
74
|
const isSiteEditor = (0, _url.getPath)(window.location.href)?.includes('site-editor.php');
|
|
73
75
|
const extraArgs = isSiteEditor ? {
|
|
74
76
|
canvas: (0, _url.getQueryArg)(window.location.href, 'canvas')
|
|
@@ -87,43 +89,38 @@ const getNavigationCommandLoaderPerPostType = postType => function useNavigation
|
|
|
87
89
|
...extraArgs
|
|
88
90
|
};
|
|
89
91
|
const targetUrl = (0, _url.addQueryArgs)('site-editor.php', args);
|
|
90
|
-
|
|
91
92
|
if (isSiteEditor) {
|
|
92
93
|
history.push(args);
|
|
93
94
|
} else {
|
|
94
95
|
document.location = targetUrl;
|
|
95
96
|
}
|
|
96
|
-
|
|
97
97
|
close();
|
|
98
98
|
}
|
|
99
99
|
};
|
|
100
100
|
});
|
|
101
|
-
}, [
|
|
101
|
+
}, [orderedRecords, history]);
|
|
102
102
|
return {
|
|
103
103
|
commands,
|
|
104
104
|
isLoading
|
|
105
105
|
};
|
|
106
106
|
};
|
|
107
|
-
|
|
108
107
|
const usePageNavigationCommandLoader = getNavigationCommandLoaderPerPostType('page');
|
|
109
108
|
const usePostNavigationCommandLoader = getNavigationCommandLoaderPerPostType('post');
|
|
110
109
|
const useTemplateNavigationCommandLoader = getNavigationCommandLoaderPerPostType('wp_template');
|
|
111
110
|
const useTemplatePartNavigationCommandLoader = getNavigationCommandLoaderPerPostType('wp_template_part');
|
|
112
|
-
|
|
113
111
|
function useSiteEditorBasicNavigationCommands() {
|
|
114
112
|
const history = useHistory();
|
|
115
113
|
const isSiteEditor = (0, _url.getPath)(window.location.href)?.includes('site-editor.php');
|
|
116
|
-
const
|
|
114
|
+
const isTemplatesAccessible = (0, _hooks.useIsTemplatesAccessible)();
|
|
115
|
+
const isBlockBasedTheme = (0, _hooks.useIsBlockBasedTheme)();
|
|
117
116
|
const commands = (0, _element.useMemo)(() => {
|
|
118
117
|
const result = [];
|
|
119
|
-
|
|
120
|
-
if (!isSiteEditorAccessible) {
|
|
118
|
+
if (!isTemplatesAccessible || !isBlockBasedTheme) {
|
|
121
119
|
return result;
|
|
122
120
|
}
|
|
123
|
-
|
|
124
121
|
result.push({
|
|
125
122
|
name: 'core/edit-site/open-navigation',
|
|
126
|
-
label: (0, _i18n.__)('
|
|
123
|
+
label: (0, _i18n.__)('Navigation'),
|
|
127
124
|
icon: _icons.navigation,
|
|
128
125
|
callback: ({
|
|
129
126
|
close
|
|
@@ -132,61 +129,55 @@ function useSiteEditorBasicNavigationCommands() {
|
|
|
132
129
|
path: '/navigation'
|
|
133
130
|
};
|
|
134
131
|
const targetUrl = (0, _url.addQueryArgs)('site-editor.php', args);
|
|
135
|
-
|
|
136
132
|
if (isSiteEditor) {
|
|
137
133
|
history.push(args);
|
|
138
134
|
} else {
|
|
139
135
|
document.location = targetUrl;
|
|
140
136
|
}
|
|
141
|
-
|
|
142
137
|
close();
|
|
143
138
|
}
|
|
144
139
|
});
|
|
145
140
|
result.push({
|
|
146
|
-
name: 'core/edit-site/open-
|
|
147
|
-
label: (0, _i18n.__)('
|
|
148
|
-
icon: _icons.
|
|
141
|
+
name: 'core/edit-site/open-styles',
|
|
142
|
+
label: (0, _i18n.__)('Styles'),
|
|
143
|
+
icon: _icons.styles,
|
|
149
144
|
callback: ({
|
|
150
145
|
close
|
|
151
146
|
}) => {
|
|
152
147
|
const args = {
|
|
153
|
-
path: '/
|
|
148
|
+
path: '/wp_global_styles'
|
|
154
149
|
};
|
|
155
150
|
const targetUrl = (0, _url.addQueryArgs)('site-editor.php', args);
|
|
156
|
-
|
|
157
151
|
if (isSiteEditor) {
|
|
158
152
|
history.push(args);
|
|
159
153
|
} else {
|
|
160
154
|
document.location = targetUrl;
|
|
161
155
|
}
|
|
162
|
-
|
|
163
156
|
close();
|
|
164
157
|
}
|
|
165
158
|
});
|
|
166
159
|
result.push({
|
|
167
|
-
name: 'core/edit-site/open-
|
|
168
|
-
label: (0, _i18n.__)('
|
|
169
|
-
icon: _icons.
|
|
160
|
+
name: 'core/edit-site/open-pages',
|
|
161
|
+
label: (0, _i18n.__)('Pages'),
|
|
162
|
+
icon: _icons.page,
|
|
170
163
|
callback: ({
|
|
171
164
|
close
|
|
172
165
|
}) => {
|
|
173
166
|
const args = {
|
|
174
|
-
path: '/
|
|
167
|
+
path: '/page'
|
|
175
168
|
};
|
|
176
169
|
const targetUrl = (0, _url.addQueryArgs)('site-editor.php', args);
|
|
177
|
-
|
|
178
170
|
if (isSiteEditor) {
|
|
179
171
|
history.push(args);
|
|
180
172
|
} else {
|
|
181
173
|
document.location = targetUrl;
|
|
182
174
|
}
|
|
183
|
-
|
|
184
175
|
close();
|
|
185
176
|
}
|
|
186
177
|
});
|
|
187
178
|
result.push({
|
|
188
179
|
name: 'core/edit-site/open-templates',
|
|
189
|
-
label: (0, _i18n.__)('
|
|
180
|
+
label: (0, _i18n.__)('Templates'),
|
|
190
181
|
icon: _icons.layout,
|
|
191
182
|
callback: ({
|
|
192
183
|
close
|
|
@@ -195,24 +186,40 @@ function useSiteEditorBasicNavigationCommands() {
|
|
|
195
186
|
path: '/wp_template'
|
|
196
187
|
};
|
|
197
188
|
const targetUrl = (0, _url.addQueryArgs)('site-editor.php', args);
|
|
198
|
-
|
|
199
189
|
if (isSiteEditor) {
|
|
200
190
|
history.push(args);
|
|
201
191
|
} else {
|
|
202
192
|
document.location = targetUrl;
|
|
203
193
|
}
|
|
204
|
-
|
|
194
|
+
close();
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
result.push({
|
|
198
|
+
name: 'core/edit-site/open-patterns',
|
|
199
|
+
label: (0, _i18n.__)('Patterns'),
|
|
200
|
+
icon: _icons.symbol,
|
|
201
|
+
callback: ({
|
|
202
|
+
close
|
|
203
|
+
}) => {
|
|
204
|
+
const args = {
|
|
205
|
+
path: '/patterns'
|
|
206
|
+
};
|
|
207
|
+
const targetUrl = (0, _url.addQueryArgs)('site-editor.php', args);
|
|
208
|
+
if (isSiteEditor) {
|
|
209
|
+
history.push(args);
|
|
210
|
+
} else {
|
|
211
|
+
document.location = targetUrl;
|
|
212
|
+
}
|
|
205
213
|
close();
|
|
206
214
|
}
|
|
207
215
|
});
|
|
208
216
|
return result;
|
|
209
|
-
}, [history, isSiteEditor,
|
|
217
|
+
}, [history, isSiteEditor, isTemplatesAccessible, isBlockBasedTheme]);
|
|
210
218
|
return {
|
|
211
219
|
commands,
|
|
212
220
|
isLoading: false
|
|
213
221
|
};
|
|
214
222
|
}
|
|
215
|
-
|
|
216
223
|
function useSiteEditorNavigationCommands() {
|
|
217
224
|
(0, _commands.useCommandLoader)({
|
|
218
225
|
name: 'core/edit-site/navigate-pages',
|
|
@@ -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","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,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,MAHhC;AAIAa,MAAAA,MAAM,EAAE,CACP,SADO,EAEP,QAFO,EAGP,OAHO,EAIP,SAJO,EAKP,SALO;AAJR,KADyB,GAazB;AACAF,MAAAA,QAAQ,EAAE,CAAC;AADX,KAbH;AAgBA,WAAO;AACNP,MAAAA,OAAO,EAAEG,gBAAgB,CAAE,UAAF,EAAcT,QAAd,EAAwBW,KAAxB,CADn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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"]}
|
|
1
|
+
{"version":3,"names":["_commands","require","_i18n","_element","_data","_coreData","_icons","_router","_url","_hooks","_lockUnlock","_orderEntityRecordsBySearch","useHistory","unlock","routerPrivateApis","icons","post","page","wp_template","layout","wp_template_part","symbolFilled","getNavigationCommandLoaderPerPostType","postType","useNavigationCommandLoader","search","history","supportsSearch","includes","records","isLoading","useSelect","select","getEntityRecords","coreStore","query","undefined","per_page","orderby","status","hasFinishedResolution","orderedRecords","useMemo","orderEntityRecordsBySearch","slice","commands","map","record","isSiteEditor","getPath","window","location","href","extraArgs","canvas","getQueryArg","name","id","searchLabel","title","rendered","label","__","icon","callback","close","args","postId","targetUrl","addQueryArgs","push","document","usePageNavigationCommandLoader","usePostNavigationCommandLoader","useTemplateNavigationCommandLoader","useTemplatePartNavigationCommandLoader","useSiteEditorBasicNavigationCommands","isTemplatesAccessible","useIsTemplatesAccessible","isBlockBasedTheme","useIsBlockBasedTheme","result","navigation","path","styles","symbol","useSiteEditorNavigationCommands","useCommandLoader","hook","context"],"sources":["@wordpress/core-commands/src/site-editor-navigation-commands.js"],"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\tsymbol,\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 { useIsTemplatesAccessible, useIsBlockBasedTheme } from './hooks';\nimport { unlock } from './lock-unlock';\nimport { orderEntityRecordsBySearch } from './utils/order-entity-records-by-search';\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\t/*\n\t\t * wp_template and wp_template_part endpoints do not support per_page or orderby parameters.\n\t\t * We need to sort the results based on the search query to avoid removing relevant\n\t\t * records below using .slice().\n\t\t */\n\t\tconst orderedRecords = useMemo( () => {\n\t\t\tif ( supportsSearch ) {\n\t\t\t\treturn records ?? [];\n\t\t\t}\n\n\t\t\treturn orderEntityRecordsBySearch( records, search ).slice( 0, 10 );\n\t\t}, [ supportsSearch, records, search ] );\n\n\t\tconst commands = useMemo( () => {\n\t\t\treturn orderedRecords.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}, [ orderedRecords, 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 isTemplatesAccessible = useIsTemplatesAccessible();\n\tconst isBlockBasedTheme = useIsBlockBasedTheme();\n\tconst commands = useMemo( () => {\n\t\tconst result = [];\n\n\t\tif ( ! isTemplatesAccessible || ! isBlockBasedTheme ) {\n\t\t\treturn result;\n\t\t}\n\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-navigation',\n\t\t\tlabel: __( '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-styles',\n\t\t\tlabel: __( 'Styles' ),\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-pages',\n\t\t\tlabel: __( '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-templates',\n\t\t\tlabel: __( '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-patterns',\n\t\t\tlabel: __( '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\n\t\treturn result;\n\t}, [ history, isSiteEditor, isTemplatesAccessible, isBlockBasedTheme ] );\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/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earch = orderEntityRecordsBySearch;
|
|
7
|
+
function orderEntityRecordsBySearch(records = [], search = '') {
|
|
8
|
+
if (!Array.isArray(records) || !records.length) {
|
|
9
|
+
return [];
|
|
10
|
+
}
|
|
11
|
+
if (!search) {
|
|
12
|
+
return records;
|
|
13
|
+
}
|
|
14
|
+
const priority = [];
|
|
15
|
+
const nonPriority = [];
|
|
16
|
+
for (let i = 0; i < records.length; i++) {
|
|
17
|
+
const record = records[i];
|
|
18
|
+
if (record?.title?.raw?.toLowerCase()?.includes(search?.toLowerCase())) {
|
|
19
|
+
priority.push(record);
|
|
20
|
+
} else {
|
|
21
|
+
nonPriority.push(record);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return priority.concat(nonPriority);
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=order-entity-records-by-search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["orderEntityRecordsBySearch","records","search","Array","isArray","length","priority","nonPriority","i","record","title","raw","toLowerCase","includes","push","concat"],"sources":["@wordpress/core-commands/src/utils/order-entity-records-by-search.js"],"sourcesContent":["export function orderEntityRecordsBySearch( records = [], search = '' ) {\n\tif ( ! Array.isArray( records ) || ! records.length ) {\n\t\treturn [];\n\t}\n\n\tif ( ! search ) {\n\t\treturn records;\n\t}\n\n\tconst priority = [];\n\tconst nonPriority = [];\n\n\tfor ( let i = 0; i < records.length; i++ ) {\n\t\tconst record = records[ i ];\n\t\tif (\n\t\t\trecord?.title?.raw?.toLowerCase()?.includes( search?.toLowerCase() )\n\t\t) {\n\t\t\tpriority.push( record );\n\t\t} else {\n\t\t\tnonPriority.push( record );\n\t\t}\n\t}\n\n\treturn priority.concat( nonPriority );\n}\n"],"mappings":";;;;;;AAAO,SAASA,0BAA0BA,CAAEC,OAAO,GAAG,EAAE,EAAEC,MAAM,GAAG,EAAE,EAAG;EACvE,IAAK,CAAEC,KAAK,CAACC,OAAO,CAAEH,OAAQ,CAAC,IAAI,CAAEA,OAAO,CAACI,MAAM,EAAG;IACrD,OAAO,EAAE;EACV;EAEA,IAAK,CAAEH,MAAM,EAAG;IACf,OAAOD,OAAO;EACf;EAEA,MAAMK,QAAQ,GAAG,EAAE;EACnB,MAAMC,WAAW,GAAG,EAAE;EAEtB,KAAM,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGP,OAAO,CAACI,MAAM,EAAEG,CAAC,EAAE,EAAG;IAC1C,MAAMC,MAAM,GAAGR,OAAO,CAAEO,CAAC,CAAE;IAC3B,IACCC,MAAM,EAAEC,KAAK,EAAEC,GAAG,EAAEC,WAAW,CAAC,CAAC,EAAEC,QAAQ,CAAEX,MAAM,EAAEU,WAAW,CAAC,CAAE,CAAC,EACnE;MACDN,QAAQ,CAACQ,IAAI,CAAEL,MAAO,CAAC;IACxB,CAAC,MAAM;MACNF,WAAW,CAACO,IAAI,CAAEL,MAAO,CAAC;IAC3B;EACD;EAEA,OAAOH,QAAQ,CAACS,MAAM,CAAER,WAAY,CAAC;AACtC"}
|
|
@@ -6,18 +6,19 @@ import { __ } from '@wordpress/i18n';
|
|
|
6
6
|
import { external, plus, symbol } from '@wordpress/icons';
|
|
7
7
|
import { addQueryArgs, getPath } from '@wordpress/url';
|
|
8
8
|
import { privateApis as routerPrivateApis } from '@wordpress/router';
|
|
9
|
+
|
|
9
10
|
/**
|
|
10
11
|
* Internal dependencies
|
|
11
12
|
*/
|
|
12
|
-
|
|
13
|
-
import { useIsSiteEditorAccessible } from './hooks';
|
|
13
|
+
import { useIsTemplatesAccessible, useIsBlockBasedTheme } from './hooks';
|
|
14
14
|
import { unlock } from './lock-unlock';
|
|
15
15
|
const {
|
|
16
16
|
useHistory
|
|
17
17
|
} = unlock(routerPrivateApis);
|
|
18
18
|
export function useAdminNavigationCommands() {
|
|
19
19
|
const history = useHistory();
|
|
20
|
-
const
|
|
20
|
+
const isTemplatesAccessible = useIsTemplatesAccessible();
|
|
21
|
+
const isBlockBasedTheme = useIsBlockBasedTheme();
|
|
21
22
|
const isSiteEditor = getPath(window.location.href)?.includes('site-editor.php');
|
|
22
23
|
useCommand({
|
|
23
24
|
name: 'core/add-new-post',
|
|
@@ -41,20 +42,18 @@ export function useAdminNavigationCommands() {
|
|
|
41
42
|
callback: ({
|
|
42
43
|
close
|
|
43
44
|
}) => {
|
|
44
|
-
if (
|
|
45
|
-
document.location.href = 'edit.php?post_type=wp_block';
|
|
46
|
-
} else {
|
|
45
|
+
if (isTemplatesAccessible && isBlockBasedTheme) {
|
|
47
46
|
const args = {
|
|
48
47
|
path: '/patterns'
|
|
49
48
|
};
|
|
50
|
-
|
|
51
49
|
if (isSiteEditor) {
|
|
52
50
|
history.push(args);
|
|
53
51
|
} else {
|
|
54
52
|
document.location = addQueryArgs('site-editor.php', args);
|
|
55
53
|
}
|
|
56
|
-
|
|
57
54
|
close();
|
|
55
|
+
} else {
|
|
56
|
+
document.location.href = 'edit.php?post_type=wp_block';
|
|
58
57
|
}
|
|
59
58
|
},
|
|
60
59
|
icon: isSiteEditor ? symbol : external
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["useCommand","__","external","plus","symbol","addQueryArgs","getPath","privateApis","routerPrivateApis","useIsTemplatesAccessible","useIsBlockBasedTheme","unlock","useHistory","useAdminNavigationCommands","history","isTemplatesAccessible","isBlockBasedTheme","isSiteEditor","window","location","href","includes","name","label","icon","callback","document","close","args","path","push"],"sources":["@wordpress/core-commands/src/admin-navigation-commands.js"],"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 { useIsTemplatesAccessible, useIsBlockBasedTheme } from './hooks';\nimport { unlock } from './lock-unlock';\n\nconst { useHistory } = unlock( routerPrivateApis );\n\nexport function useAdminNavigationCommands() {\n\tconst history = useHistory();\n\tconst isTemplatesAccessible = useIsTemplatesAccessible();\n\tconst isBlockBasedTheme = useIsBlockBasedTheme();\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 ( isTemplatesAccessible && isBlockBasedTheme ) {\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} else {\n\t\t\t\tdocument.location.href = 'edit.php?post_type=wp_block';\n\t\t\t}\n\t\t},\n\t\ticon: isSiteEditor ? symbol : external,\n\t} );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,UAAU,QAAQ,qBAAqB;AAChD,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,QAAQ,EAAEC,IAAI,EAAEC,MAAM,QAAQ,kBAAkB;AACzD,SAASC,YAAY,EAAEC,OAAO,QAAQ,gBAAgB;AACtD,SAASC,WAAW,IAAIC,iBAAiB,QAAQ,mBAAmB;;AAEpE;AACA;AACA;AACA,SAASC,wBAAwB,EAAEC,oBAAoB,QAAQ,SAAS;AACxE,SAASC,MAAM,QAAQ,eAAe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,CAAC;QAC5D;QACAD,KAAK,CAAC,CAAC;MACR,CAAC,MAAM;QACND,QAAQ,CAACP,QAAQ,CAACC,IAAI,GAAG,6BAA6B;MACvD;IACD,CAAC;IACDI,IAAI,EAAEP,YAAY,GAAGb,MAAM,GAAGF;EAC/B,CAAE,CAAC;AACJ"}
|
package/build-module/hooks.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
5
4
|
import { store as coreStore } from '@wordpress/core-data';
|
|
6
5
|
import { useSelect } from '@wordpress/data';
|
|
7
|
-
export function
|
|
8
|
-
return useSelect(select => select(
|
|
6
|
+
export function useIsTemplatesAccessible() {
|
|
7
|
+
return useSelect(select => select(coreStore).canUser('read', 'templates'), []);
|
|
8
|
+
}
|
|
9
|
+
export function useIsBlockBasedTheme() {
|
|
10
|
+
return useSelect(select => select(coreStore).getCurrentTheme()?.is_block_theme, []);
|
|
9
11
|
}
|
|
10
12
|
//# sourceMappingURL=hooks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["store","coreStore","useSelect","useIsTemplatesAccessible","select","canUser","useIsBlockBasedTheme","getCurrentTheme","is_block_theme"],"sources":["@wordpress/core-commands/src/hooks.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useSelect } from '@wordpress/data';\n\nexport function useIsTemplatesAccessible() {\n\treturn useSelect(\n\t\t( select ) => select( coreStore ).canUser( 'read', 'templates' ),\n\t\t[]\n\t);\n}\n\nexport function useIsBlockBasedTheme() {\n\treturn useSelect(\n\t\t( select ) => select( coreStore ).getCurrentTheme()?.is_block_theme,\n\t\t[]\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASC,SAAS,QAAQ,iBAAiB;AAE3C,OAAO,SAASC,wBAAwBA,CAAA,EAAG;EAC1C,OAAOD,SAAS,CACbE,MAAM,IAAMA,MAAM,CAAEH,SAAU,CAAC,CAACI,OAAO,CAAE,MAAM,EAAE,WAAY,CAAC,EAChE,EACD,CAAC;AACF;AAEA,OAAO,SAASC,oBAAoBA,CAAA,EAAG;EACtC,OAAOJ,SAAS,CACbE,MAAM,IAAMA,MAAM,CAAEH,SAAU,CAAC,CAACM,eAAe,CAAC,CAAC,EAAEC,cAAc,EACnE,EACD,CAAC;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-commands/src/index.js"],"
|
|
1
|
+
{"version":3,"names":["privateApis"],"sources":["@wordpress/core-commands/src/index.js"],"sourcesContent":["export { privateApis } from './private-apis';\n"],"mappings":"AAAA,SAASA,WAAW,QAAQ,gBAAgB"}
|