@wordpress/core-commands 0.2.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 +7 -0
- package/LICENSE.md +788 -0
- package/README.md +31 -0
- package/build/add-post-type-commands.js +45 -0
- package/build/add-post-type-commands.js.map +1 -0
- package/build/index.js +14 -0
- package/build/index.js.map +1 -0
- package/build/lock-unlock.js +19 -0
- package/build/lock-unlock.js.map +1 -0
- package/build/private-apis.js +27 -0
- package/build/private-apis.js.map +1 -0
- package/build/site-editor-navigation-commands.js +143 -0
- package/build/site-editor-navigation-commands.js.map +1 -0
- package/build-module/add-post-type-commands.js +33 -0
- package/build-module/add-post-type-commands.js.map +1 -0
- package/build-module/index.js +2 -0
- package/build-module/index.js.map +1 -0
- package/build-module/lock-unlock.js +9 -0
- package/build-module/lock-unlock.js.map +1 -0
- package/build-module/private-apis.js +17 -0
- package/build-module/private-apis.js.map +1 -0
- package/build-module/site-editor-navigation-commands.js +126 -0
- package/build-module/site-editor-navigation-commands.js.map +1 -0
- package/package.json +47 -0
- package/src/add-post-type-commands.js +32 -0
- package/src/index.js +1 -0
- package/src/lock-unlock.js +10 -0
- package/src/private-apis.js +16 -0
- package/src/site-editor-navigation-commands.js +129 -0
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Core Commands
|
|
2
|
+
|
|
3
|
+
This package includes a list of reusable WordPress Admin commands. These commands can be used in multiple WP Admin pages.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install the module
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @wordpress/core-commands --save
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
_This package assumes that your code will run in an **ES2015+** environment. If you're using an environment that has limited or no support for such language features and APIs, you should include [the polyfill shipped in `@wordpress/babel-preset-default`](https://github.com/WordPress/gutenberg/tree/HEAD/packages/babel-preset-default#polyfill) in your code._
|
|
14
|
+
|
|
15
|
+
## API
|
|
16
|
+
|
|
17
|
+
<!-- START TOKEN(Autogenerated API docs) -->
|
|
18
|
+
|
|
19
|
+
### privateApis
|
|
20
|
+
|
|
21
|
+
Undocumented declaration.
|
|
22
|
+
|
|
23
|
+
<!-- END TOKEN(Autogenerated API docs) -->
|
|
24
|
+
|
|
25
|
+
## Contributing to this package
|
|
26
|
+
|
|
27
|
+
This is an individual package that's part of the Gutenberg project. The project is organized as a monorepo. It's made up of multiple self-contained software packages, each with a specific purpose. The packages in this monorepo are published to [npm](https://www.npmjs.com/) and used by [WordPress](https://make.wordpress.org/core/) as well as other software projects.
|
|
28
|
+
|
|
29
|
+
To find out more about contributing to this package or Gutenberg as a whole, please read the project's main [contributor guide](https://github.com/WordPress/gutenberg/tree/HEAD/CONTRIBUTING.md).
|
|
30
|
+
|
|
31
|
+
<br /><br /><p align="center"><img src="https://s.w.org/style/images/codeispoetry.png?1" alt="Code is Poetry." /></p>
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useAddPostTypeCommands = useAddPostTypeCommands;
|
|
7
|
+
|
|
8
|
+
var _commands = require("@wordpress/commands");
|
|
9
|
+
|
|
10
|
+
var _i18n = require("@wordpress/i18n");
|
|
11
|
+
|
|
12
|
+
var _icons = require("@wordpress/icons");
|
|
13
|
+
|
|
14
|
+
var _lockUnlock = require("./lock-unlock");
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* WordPress dependencies
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Internal dependencies
|
|
22
|
+
*/
|
|
23
|
+
const {
|
|
24
|
+
useCommand
|
|
25
|
+
} = (0, _lockUnlock.unlock)(_commands.privateApis);
|
|
26
|
+
|
|
27
|
+
function useAddPostTypeCommands() {
|
|
28
|
+
useCommand({
|
|
29
|
+
name: 'add new post',
|
|
30
|
+
label: (0, _i18n.__)('Add new post'),
|
|
31
|
+
icon: _icons.plus,
|
|
32
|
+
callback: () => {
|
|
33
|
+
document.location.href = 'post-new.php';
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
useCommand({
|
|
37
|
+
name: 'add new page',
|
|
38
|
+
label: (0, _i18n.__)('Add new page'),
|
|
39
|
+
icon: _icons.plus,
|
|
40
|
+
callback: () => {
|
|
41
|
+
document.location.href = 'post-new.php?post_type=page';
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=add-post-type-commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-commands/src/add-post-type-commands.js"],"names":["useCommand","privateApis","useAddPostTypeCommands","name","label","icon","plus","callback","document","location","href"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AAKA;;AAVA;AACA;AACA;;AAKA;AACA;AACA;AAGA,MAAM;AAAEA,EAAAA;AAAF,IAAiB,wBAAQC,qBAAR,CAAvB;;AAEO,SAASC,sBAAT,GAAkC;AACxCF,EAAAA,UAAU,CAAE;AACXG,IAAAA,IAAI,EAAE,cADK;AAEXC,IAAAA,KAAK,EAAE,cAAI,cAAJ,CAFI;AAGXC,IAAAA,IAAI,EAAEC,WAHK;AAIXC,IAAAA,QAAQ,EAAE,MAAM;AACfC,MAAAA,QAAQ,CAACC,QAAT,CAAkBC,IAAlB,GAAyB,cAAzB;AACA;AANU,GAAF,CAAV;AAQAV,EAAAA,UAAU,CAAE;AACXG,IAAAA,IAAI,EAAE,cADK;AAEXC,IAAAA,KAAK,EAAE,cAAI,cAAJ,CAFI;AAGXC,IAAAA,IAAI,EAAEC,WAHK;AAIXC,IAAAA,QAAQ,EAAE,MAAM;AACfC,MAAAA,QAAQ,CAACC,QAAT,CAAkBC,IAAlB,GAAyB,6BAAzB;AACA;AANU,GAAF,CAAV;AAQA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { privateApis } from '@wordpress/commands';\nimport { __ } from '@wordpress/i18n';\nimport { plus } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from './lock-unlock';\n\nconst { useCommand } = unlock( privateApis );\n\nexport function useAddPostTypeCommands() {\n\tuseCommand( {\n\t\tname: '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: 'add new page',\n\t\tlabel: __( 'Add new page' ),\n\t\ticon: plus,\n\t\tcallback: () => {\n\t\t\tdocument.location.href = 'post-new.php?post_type=page';\n\t\t},\n\t} );\n}\n"]}
|
package/build/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "privateApis", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _privateApis.privateApis;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
var _privateApis = require("./private-apis");
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-commands/src/index.js"],"names":[],"mappings":";;;;;;;;;;;;AAAA","sourcesContent":["export { privateApis } from './private-apis';\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.unlock = exports.lock = void 0;
|
|
7
|
+
|
|
8
|
+
var _privateApis = require("@wordpress/private-apis");
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* WordPress dependencies
|
|
12
|
+
*/
|
|
13
|
+
const {
|
|
14
|
+
lock,
|
|
15
|
+
unlock
|
|
16
|
+
} = (0, _privateApis.__dangerousOptInToUnstableAPIsOnlyForCoreModules)('I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.', '@wordpress/core-commands');
|
|
17
|
+
exports.unlock = unlock;
|
|
18
|
+
exports.lock = lock;
|
|
19
|
+
//# sourceMappingURL=lock-unlock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-commands/src/lock-unlock.js"],"names":["lock","unlock"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;AAGO,MAAM;AAAEA,EAAAA,IAAF;AAAQC,EAAAA;AAAR,IACZ,mEACC,8GADD,EAEC,0BAFD,CADM","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"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.privateApis = void 0;
|
|
7
|
+
|
|
8
|
+
var _addPostTypeCommands = require("./add-post-type-commands");
|
|
9
|
+
|
|
10
|
+
var _siteEditorNavigationCommands = require("./site-editor-navigation-commands");
|
|
11
|
+
|
|
12
|
+
var _lockUnlock = require("./lock-unlock");
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Internal dependencies
|
|
16
|
+
*/
|
|
17
|
+
function useCommands() {
|
|
18
|
+
(0, _addPostTypeCommands.useAddPostTypeCommands)();
|
|
19
|
+
(0, _siteEditorNavigationCommands.useSiteEditorNavigationCommands)();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const privateApis = {};
|
|
23
|
+
exports.privateApis = privateApis;
|
|
24
|
+
(0, _lockUnlock.lock)(privateApis, {
|
|
25
|
+
useCommands
|
|
26
|
+
});
|
|
27
|
+
//# sourceMappingURL=private-apis.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-commands/src/private-apis.js"],"names":["useCommands","privateApis"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AALA;AACA;AACA;AAKA,SAASA,WAAT,GAAuB;AACtB;AACA;AACA;;AAEM,MAAMC,WAAW,GAAG,EAApB;;AACP,sBAAMA,WAAN,EAAmB;AAClBD,EAAAA;AADkB,CAAnB","sourcesContent":["/**\n * Internal dependencies\n */\nimport { useAddPostTypeCommands } from './add-post-type-commands';\nimport { useSiteEditorNavigationCommands } from './site-editor-navigation-commands';\nimport { lock } from './lock-unlock';\n\nfunction useCommands() {\n\tuseAddPostTypeCommands();\n\tuseSiteEditorNavigationCommands();\n}\n\nexport const privateApis = {};\nlock( privateApis, {\n\tuseCommands,\n} );\n"]}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useSiteEditorNavigationCommands = useSiteEditorNavigationCommands;
|
|
7
|
+
|
|
8
|
+
var _commands = require("@wordpress/commands");
|
|
9
|
+
|
|
10
|
+
var _i18n = require("@wordpress/i18n");
|
|
11
|
+
|
|
12
|
+
var _element = require("@wordpress/element");
|
|
13
|
+
|
|
14
|
+
var _data = require("@wordpress/data");
|
|
15
|
+
|
|
16
|
+
var _coreData = require("@wordpress/core-data");
|
|
17
|
+
|
|
18
|
+
var _icons = require("@wordpress/icons");
|
|
19
|
+
|
|
20
|
+
var _router = require("@wordpress/router");
|
|
21
|
+
|
|
22
|
+
var _url = require("@wordpress/url");
|
|
23
|
+
|
|
24
|
+
var _lockUnlock = require("./lock-unlock");
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* WordPress dependencies
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Internal dependencies
|
|
32
|
+
*/
|
|
33
|
+
const {
|
|
34
|
+
useCommandLoader
|
|
35
|
+
} = (0, _lockUnlock.unlock)(_commands.privateApis);
|
|
36
|
+
const {
|
|
37
|
+
useHistory
|
|
38
|
+
} = (0, _lockUnlock.unlock)(_router.privateApis);
|
|
39
|
+
const icons = {
|
|
40
|
+
post: _icons.post,
|
|
41
|
+
page: _icons.page,
|
|
42
|
+
wp_template: _icons.layout,
|
|
43
|
+
wp_template_part: _icons.symbolFilled
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const getNavigationCommandLoaderPerPostType = postType => function useNavigationCommandLoader(_ref) {
|
|
47
|
+
let {
|
|
48
|
+
search
|
|
49
|
+
} = _ref;
|
|
50
|
+
const history = useHistory();
|
|
51
|
+
const supportsSearch = !['wp_template', 'wp_template_part'].includes(postType);
|
|
52
|
+
const deps = supportsSearch ? [search] : [];
|
|
53
|
+
const {
|
|
54
|
+
records,
|
|
55
|
+
isLoading
|
|
56
|
+
} = (0, _data.useSelect)(select => {
|
|
57
|
+
const {
|
|
58
|
+
getEntityRecords
|
|
59
|
+
} = select(_coreData.store);
|
|
60
|
+
const query = supportsSearch ? {
|
|
61
|
+
search: !!search ? search : undefined,
|
|
62
|
+
per_page: 10,
|
|
63
|
+
orderby: search ? 'relevance' : 'date'
|
|
64
|
+
} : {
|
|
65
|
+
per_page: -1
|
|
66
|
+
};
|
|
67
|
+
return {
|
|
68
|
+
records: getEntityRecords('postType', postType, query),
|
|
69
|
+
isLoading: !select(_coreData.store).hasFinishedResolution('getEntityRecords', ['postType', postType, query]),
|
|
70
|
+
// We're using the string literal to check whether we're in the site editor.
|
|
71
|
+
|
|
72
|
+
/* eslint-disable-next-line @wordpress/data-no-store-string-literals */
|
|
73
|
+
isSiteEditor: !!select('edit-site')
|
|
74
|
+
};
|
|
75
|
+
}, deps);
|
|
76
|
+
const commands = (0, _element.useMemo)(() => {
|
|
77
|
+
return (records !== null && records !== void 0 ? records : []).slice(0, 10).map(record => {
|
|
78
|
+
var _getPath, _record$title, _record$title2, _record$title3;
|
|
79
|
+
|
|
80
|
+
const isSiteEditor = (_getPath = (0, _url.getPath)(window.location.href)) === null || _getPath === void 0 ? void 0 : _getPath.includes('site-editor.php');
|
|
81
|
+
const extraArgs = isSiteEditor ? {
|
|
82
|
+
canvas: (0, _url.getQueryArg)(window.location.href, 'canvas')
|
|
83
|
+
} : {};
|
|
84
|
+
return {
|
|
85
|
+
name: ((_record$title = record.title) === null || _record$title === void 0 ? void 0 : _record$title.rendered) + ' ' + record.id,
|
|
86
|
+
label: (_record$title2 = record.title) !== null && _record$title2 !== void 0 && _record$title2.rendered ? (_record$title3 = record.title) === null || _record$title3 === void 0 ? void 0 : _record$title3.rendered : (0, _i18n.__)('(no title)'),
|
|
87
|
+
icon: icons[postType],
|
|
88
|
+
callback: _ref2 => {
|
|
89
|
+
let {
|
|
90
|
+
close
|
|
91
|
+
} = _ref2;
|
|
92
|
+
const args = {
|
|
93
|
+
postType,
|
|
94
|
+
postId: record.id,
|
|
95
|
+
...extraArgs
|
|
96
|
+
};
|
|
97
|
+
const targetUrl = (0, _url.addQueryArgs)('site-editor.php', args);
|
|
98
|
+
|
|
99
|
+
if (isSiteEditor) {
|
|
100
|
+
history.push(args);
|
|
101
|
+
} else {
|
|
102
|
+
document.location = targetUrl;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
close();
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
}, [records, history]);
|
|
110
|
+
return {
|
|
111
|
+
commands,
|
|
112
|
+
isLoading
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const usePageNavigationCommandLoader = getNavigationCommandLoaderPerPostType('page');
|
|
117
|
+
const usePostNavigationCommandLoader = getNavigationCommandLoaderPerPostType('post');
|
|
118
|
+
const useTemplateNavigationCommandLoader = getNavigationCommandLoaderPerPostType('wp_template');
|
|
119
|
+
const useTemplatePartNavigationCommandLoader = getNavigationCommandLoaderPerPostType('wp_template_part');
|
|
120
|
+
|
|
121
|
+
function useSiteEditorNavigationCommands() {
|
|
122
|
+
useCommandLoader({
|
|
123
|
+
name: 'core/edit-site/navigate-pages',
|
|
124
|
+
group: (0, _i18n.__)('Pages'),
|
|
125
|
+
hook: usePageNavigationCommandLoader
|
|
126
|
+
});
|
|
127
|
+
useCommandLoader({
|
|
128
|
+
name: 'core/edit-site/navigate-posts',
|
|
129
|
+
group: (0, _i18n.__)('Posts'),
|
|
130
|
+
hook: usePostNavigationCommandLoader
|
|
131
|
+
});
|
|
132
|
+
useCommandLoader({
|
|
133
|
+
name: 'core/edit-site/navigate-templates',
|
|
134
|
+
group: (0, _i18n.__)('Templates'),
|
|
135
|
+
hook: useTemplateNavigationCommandLoader
|
|
136
|
+
});
|
|
137
|
+
useCommandLoader({
|
|
138
|
+
name: 'core/edit-site/navigate-template-parts',
|
|
139
|
+
group: (0, _i18n.__)('Template Parts'),
|
|
140
|
+
hook: useTemplatePartNavigationCommandLoader
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=site-editor-navigation-commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-commands/src/site-editor-navigation-commands.js"],"names":["useCommandLoader","privateApis","useHistory","routerPrivateApis","icons","post","page","wp_template","layout","wp_template_part","symbolFilled","getNavigationCommandLoaderPerPostType","postType","useNavigationCommandLoader","search","history","supportsSearch","includes","deps","records","isLoading","select","getEntityRecords","coreStore","query","undefined","per_page","orderby","hasFinishedResolution","isSiteEditor","commands","slice","map","record","window","location","href","extraArgs","canvas","name","title","rendered","id","label","icon","callback","close","args","postId","targetUrl","push","document","usePageNavigationCommandLoader","usePostNavigationCommandLoader","useTemplateNavigationCommandLoader","useTemplatePartNavigationComm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EAAE,cAAI,gBAAJ,CAFU;AAGjBC,IAAAA,IAAI,EAAEH;AAHW,GAAF,CAAhB;AAKA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { privateApis } from '@wordpress/commands';\nimport { __ } from '@wordpress/i18n';\nimport { useMemo } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { post, page, layout, symbolFilled } from '@wordpress/icons';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { getQueryArg, addQueryArgs, getPath } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from './lock-unlock';\n\nconst { useCommandLoader } = unlock( privateApis );\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 deps = supportsSearch ? [ search ] : [];\n\t\tconst { records, isLoading } = useSelect( ( select ) => {\n\t\t\tconst { getEntityRecords } = select( coreStore );\n\t\t\tconst query = supportsSearch\n\t\t\t\t? {\n\t\t\t\t\t\tsearch: !! search ? search : undefined,\n\t\t\t\t\t\tper_page: 10,\n\t\t\t\t\t\torderby: search ? 'relevance' : 'date',\n\t\t\t\t }\n\t\t\t\t: {\n\t\t\t\t\t\tper_page: -1,\n\t\t\t\t };\n\t\t\treturn {\n\t\t\t\trecords: getEntityRecords( 'postType', postType, query ),\n\t\t\t\tisLoading: ! select( coreStore ).hasFinishedResolution(\n\t\t\t\t\t'getEntityRecords',\n\t\t\t\t\t[ 'postType', postType, query ]\n\t\t\t\t),\n\t\t\t\t// We're using the string literal to check whether we're in the site editor.\n\t\t\t\t/* eslint-disable-next-line @wordpress/data-no-store-string-literals */\n\t\t\t\tisSiteEditor: !! select( 'edit-site' ),\n\t\t\t};\n\t\t}, deps );\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: record.title?.rendered + ' ' + record.id,\n\t\t\t\t\tlabel: record.title?.rendered\n\t\t\t\t\t\t? record.title?.rendered\n\t\t\t\t\t\t: __( '(no title)' ),\n\t\t\t\t\ticon: icons[ postType ],\n\t\t\t\t\tcallback: ( { close } ) => {\n\t\t\t\t\t\tconst args = {\n\t\t\t\t\t\t\tpostType,\n\t\t\t\t\t\t\tpostId: record.id,\n\t\t\t\t\t\t\t...extraArgs,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tconst targetUrl = addQueryArgs(\n\t\t\t\t\t\t\t'site-editor.php',\n\t\t\t\t\t\t\targs\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\t\t\thistory.push( args );\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tclose();\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t} );\n\t\t}, [ records, history ] );\n\n\t\treturn {\n\t\t\tcommands,\n\t\t\tisLoading,\n\t\t};\n\t};\n\nconst usePageNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'page' );\nconst usePostNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'post' );\nconst useTemplateNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'wp_template' );\nconst useTemplatePartNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'wp_template_part' );\n\nexport function useSiteEditorNavigationCommands() {\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-pages',\n\t\tgroup: __( 'Pages' ),\n\t\thook: usePageNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-posts',\n\t\tgroup: __( 'Posts' ),\n\t\thook: usePostNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-templates',\n\t\tgroup: __( 'Templates' ),\n\t\thook: useTemplateNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-template-parts',\n\t\tgroup: __( 'Template Parts' ),\n\t\thook: useTemplatePartNavigationCommandLoader,\n\t} );\n}\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { privateApis } from '@wordpress/commands';
|
|
5
|
+
import { __ } from '@wordpress/i18n';
|
|
6
|
+
import { plus } from '@wordpress/icons';
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { unlock } from './lock-unlock';
|
|
12
|
+
const {
|
|
13
|
+
useCommand
|
|
14
|
+
} = unlock(privateApis);
|
|
15
|
+
export function useAddPostTypeCommands() {
|
|
16
|
+
useCommand({
|
|
17
|
+
name: 'add new post',
|
|
18
|
+
label: __('Add new post'),
|
|
19
|
+
icon: plus,
|
|
20
|
+
callback: () => {
|
|
21
|
+
document.location.href = 'post-new.php';
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
useCommand({
|
|
25
|
+
name: 'add new page',
|
|
26
|
+
label: __('Add new page'),
|
|
27
|
+
icon: plus,
|
|
28
|
+
callback: () => {
|
|
29
|
+
document.location.href = 'post-new.php?post_type=page';
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=add-post-type-commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-commands/src/add-post-type-commands.js"],"names":["privateApis","__","plus","unlock","useCommand","useAddPostTypeCommands","name","label","icon","callback","document","location","href"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAT,QAA4B,qBAA5B;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,IAAT,QAAqB,kBAArB;AAEA;AACA;AACA;;AACA,SAASC,MAAT,QAAuB,eAAvB;AAEA,MAAM;AAAEC,EAAAA;AAAF,IAAiBD,MAAM,CAAEH,WAAF,CAA7B;AAEA,OAAO,SAASK,sBAAT,GAAkC;AACxCD,EAAAA,UAAU,CAAE;AACXE,IAAAA,IAAI,EAAE,cADK;AAEXC,IAAAA,KAAK,EAAEN,EAAE,CAAE,cAAF,CAFE;AAGXO,IAAAA,IAAI,EAAEN,IAHK;AAIXO,IAAAA,QAAQ,EAAE,MAAM;AACfC,MAAAA,QAAQ,CAACC,QAAT,CAAkBC,IAAlB,GAAyB,cAAzB;AACA;AANU,GAAF,CAAV;AAQAR,EAAAA,UAAU,CAAE;AACXE,IAAAA,IAAI,EAAE,cADK;AAEXC,IAAAA,KAAK,EAAEN,EAAE,CAAE,cAAF,CAFE;AAGXO,IAAAA,IAAI,EAAEN,IAHK;AAIXO,IAAAA,QAAQ,EAAE,MAAM;AACfC,MAAAA,QAAQ,CAACC,QAAT,CAAkBC,IAAlB,GAAyB,6BAAzB;AACA;AANU,GAAF,CAAV;AAQA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { privateApis } from '@wordpress/commands';\nimport { __ } from '@wordpress/i18n';\nimport { plus } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from './lock-unlock';\n\nconst { useCommand } = unlock( privateApis );\n\nexport function useAddPostTypeCommands() {\n\tuseCommand( {\n\t\tname: '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: 'add new page',\n\t\tlabel: __( 'Add new page' ),\n\t\ticon: plus,\n\t\tcallback: () => {\n\t\t\tdocument.location.href = 'post-new.php?post_type=page';\n\t\t},\n\t} );\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-commands/src/index.js"],"names":["privateApis"],"mappings":"AAAA,SAASA,WAAT,QAA4B,gBAA5B","sourcesContent":["export { privateApis } from './private-apis';\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';
|
|
5
|
+
export const {
|
|
6
|
+
lock,
|
|
7
|
+
unlock
|
|
8
|
+
} = __dangerousOptInToUnstableAPIsOnlyForCoreModules('I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.', '@wordpress/core-commands');
|
|
9
|
+
//# sourceMappingURL=lock-unlock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-commands/src/lock-unlock.js"],"names":["__dangerousOptInToUnstableAPIsOnlyForCoreModules","lock","unlock"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,gDAAT,QAAiE,yBAAjE;AAEA,OAAO,MAAM;AAAEC,EAAAA,IAAF;AAAQC,EAAAA;AAAR,IACZF,gDAAgD,CAC/C,8GAD+C,EAE/C,0BAF+C,CAD1C","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"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useAddPostTypeCommands } from './add-post-type-commands';
|
|
5
|
+
import { useSiteEditorNavigationCommands } from './site-editor-navigation-commands';
|
|
6
|
+
import { lock } from './lock-unlock';
|
|
7
|
+
|
|
8
|
+
function useCommands() {
|
|
9
|
+
useAddPostTypeCommands();
|
|
10
|
+
useSiteEditorNavigationCommands();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const privateApis = {};
|
|
14
|
+
lock(privateApis, {
|
|
15
|
+
useCommands
|
|
16
|
+
});
|
|
17
|
+
//# sourceMappingURL=private-apis.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-commands/src/private-apis.js"],"names":["useAddPostTypeCommands","useSiteEditorNavigationCommands","lock","useCommands","privateApis"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,sBAAT,QAAuC,0BAAvC;AACA,SAASC,+BAAT,QAAgD,mCAAhD;AACA,SAASC,IAAT,QAAqB,eAArB;;AAEA,SAASC,WAAT,GAAuB;AACtBH,EAAAA,sBAAsB;AACtBC,EAAAA,+BAA+B;AAC/B;;AAED,OAAO,MAAMG,WAAW,GAAG,EAApB;AACPF,IAAI,CAAEE,WAAF,EAAe;AAClBD,EAAAA;AADkB,CAAf,CAAJ","sourcesContent":["/**\n * Internal dependencies\n */\nimport { useAddPostTypeCommands } from './add-post-type-commands';\nimport { useSiteEditorNavigationCommands } from './site-editor-navigation-commands';\nimport { lock } from './lock-unlock';\n\nfunction useCommands() {\n\tuseAddPostTypeCommands();\n\tuseSiteEditorNavigationCommands();\n}\n\nexport const privateApis = {};\nlock( privateApis, {\n\tuseCommands,\n} );\n"]}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { privateApis } from '@wordpress/commands';
|
|
5
|
+
import { __ } from '@wordpress/i18n';
|
|
6
|
+
import { useMemo } from '@wordpress/element';
|
|
7
|
+
import { useSelect } from '@wordpress/data';
|
|
8
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
9
|
+
import { post, page, layout, symbolFilled } from '@wordpress/icons';
|
|
10
|
+
import { privateApis as routerPrivateApis } from '@wordpress/router';
|
|
11
|
+
import { getQueryArg, addQueryArgs, getPath } from '@wordpress/url';
|
|
12
|
+
/**
|
|
13
|
+
* Internal dependencies
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { unlock } from './lock-unlock';
|
|
17
|
+
const {
|
|
18
|
+
useCommandLoader
|
|
19
|
+
} = unlock(privateApis);
|
|
20
|
+
const {
|
|
21
|
+
useHistory
|
|
22
|
+
} = unlock(routerPrivateApis);
|
|
23
|
+
const icons = {
|
|
24
|
+
post,
|
|
25
|
+
page,
|
|
26
|
+
wp_template: layout,
|
|
27
|
+
wp_template_part: symbolFilled
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const getNavigationCommandLoaderPerPostType = postType => function useNavigationCommandLoader(_ref) {
|
|
31
|
+
let {
|
|
32
|
+
search
|
|
33
|
+
} = _ref;
|
|
34
|
+
const history = useHistory();
|
|
35
|
+
const supportsSearch = !['wp_template', 'wp_template_part'].includes(postType);
|
|
36
|
+
const deps = supportsSearch ? [search] : [];
|
|
37
|
+
const {
|
|
38
|
+
records,
|
|
39
|
+
isLoading
|
|
40
|
+
} = useSelect(select => {
|
|
41
|
+
const {
|
|
42
|
+
getEntityRecords
|
|
43
|
+
} = select(coreStore);
|
|
44
|
+
const query = supportsSearch ? {
|
|
45
|
+
search: !!search ? search : undefined,
|
|
46
|
+
per_page: 10,
|
|
47
|
+
orderby: search ? 'relevance' : 'date'
|
|
48
|
+
} : {
|
|
49
|
+
per_page: -1
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
records: getEntityRecords('postType', postType, query),
|
|
53
|
+
isLoading: !select(coreStore).hasFinishedResolution('getEntityRecords', ['postType', postType, query]),
|
|
54
|
+
// We're using the string literal to check whether we're in the site editor.
|
|
55
|
+
|
|
56
|
+
/* eslint-disable-next-line @wordpress/data-no-store-string-literals */
|
|
57
|
+
isSiteEditor: !!select('edit-site')
|
|
58
|
+
};
|
|
59
|
+
}, deps);
|
|
60
|
+
const commands = useMemo(() => {
|
|
61
|
+
return (records !== null && records !== void 0 ? records : []).slice(0, 10).map(record => {
|
|
62
|
+
var _getPath, _record$title, _record$title2, _record$title3;
|
|
63
|
+
|
|
64
|
+
const isSiteEditor = (_getPath = getPath(window.location.href)) === null || _getPath === void 0 ? void 0 : _getPath.includes('site-editor.php');
|
|
65
|
+
const extraArgs = isSiteEditor ? {
|
|
66
|
+
canvas: getQueryArg(window.location.href, 'canvas')
|
|
67
|
+
} : {};
|
|
68
|
+
return {
|
|
69
|
+
name: ((_record$title = record.title) === null || _record$title === void 0 ? void 0 : _record$title.rendered) + ' ' + record.id,
|
|
70
|
+
label: (_record$title2 = record.title) !== null && _record$title2 !== void 0 && _record$title2.rendered ? (_record$title3 = record.title) === null || _record$title3 === void 0 ? void 0 : _record$title3.rendered : __('(no title)'),
|
|
71
|
+
icon: icons[postType],
|
|
72
|
+
callback: _ref2 => {
|
|
73
|
+
let {
|
|
74
|
+
close
|
|
75
|
+
} = _ref2;
|
|
76
|
+
const args = {
|
|
77
|
+
postType,
|
|
78
|
+
postId: record.id,
|
|
79
|
+
...extraArgs
|
|
80
|
+
};
|
|
81
|
+
const targetUrl = addQueryArgs('site-editor.php', args);
|
|
82
|
+
|
|
83
|
+
if (isSiteEditor) {
|
|
84
|
+
history.push(args);
|
|
85
|
+
} else {
|
|
86
|
+
document.location = targetUrl;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
close();
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
});
|
|
93
|
+
}, [records, history]);
|
|
94
|
+
return {
|
|
95
|
+
commands,
|
|
96
|
+
isLoading
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const usePageNavigationCommandLoader = getNavigationCommandLoaderPerPostType('page');
|
|
101
|
+
const usePostNavigationCommandLoader = getNavigationCommandLoaderPerPostType('post');
|
|
102
|
+
const useTemplateNavigationCommandLoader = getNavigationCommandLoaderPerPostType('wp_template');
|
|
103
|
+
const useTemplatePartNavigationCommandLoader = getNavigationCommandLoaderPerPostType('wp_template_part');
|
|
104
|
+
export function useSiteEditorNavigationCommands() {
|
|
105
|
+
useCommandLoader({
|
|
106
|
+
name: 'core/edit-site/navigate-pages',
|
|
107
|
+
group: __('Pages'),
|
|
108
|
+
hook: usePageNavigationCommandLoader
|
|
109
|
+
});
|
|
110
|
+
useCommandLoader({
|
|
111
|
+
name: 'core/edit-site/navigate-posts',
|
|
112
|
+
group: __('Posts'),
|
|
113
|
+
hook: usePostNavigationCommandLoader
|
|
114
|
+
});
|
|
115
|
+
useCommandLoader({
|
|
116
|
+
name: 'core/edit-site/navigate-templates',
|
|
117
|
+
group: __('Templates'),
|
|
118
|
+
hook: useTemplateNavigationCommandLoader
|
|
119
|
+
});
|
|
120
|
+
useCommandLoader({
|
|
121
|
+
name: 'core/edit-site/navigate-template-parts',
|
|
122
|
+
group: __('Template Parts'),
|
|
123
|
+
hook: useTemplatePartNavigationCommandLoader
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=site-editor-navigation-commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-commands/src/site-editor-navigation-commands.js"],"names":["privateApis","__","useMemo","useSelect","store","coreStore","post","page","layout","symbolFilled","routerPrivateApis","getQueryArg","addQueryArgs","getPath","unlock","useCommandLoader","useHistory","icons","wp_template","wp_template_part","getNavigationCommandLoaderPerPostType","postType","useNavigationCommandLoader","search","history","supportsSearch","includes","deps","records","isLoading","select","getEntityRecords","query","undefined","per_page","orderby","hasFinishedResolution","isSiteEditor","commands","slice","map","record","window","location","href","extraArgs","canvas","name","title","rendered","id","label","icon","callback","close","args","postId","targetUrl","push","document","usePageNavigationCommandLoader","usePostNavigationCommandLoader","useTemplateNavigationCommandLoader","useTemplatePartNavigationCommandLoader","useSiteEditorNavigationCommands","group","hook"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAT,QAA4B,qBAA5B;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,OAAT,QAAwB,oBAAxB;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,sBAAnC;AACA,SAASC,IAAT,EAAeC,IAAf,EAAqBC,MAArB,EAA6BC,YAA7B,QAAiD,kBAAjD;AACA,SAAST,WAAW,IAAIU,iBAAxB,QAAiD,mBAAjD;AACA,SAASC,WAAT,EAAsBC,YAAtB,EAAoCC,OAApC,QAAmD,gBAAnD;AAEA;AACA;AACA;;AACA,SAASC,MAAT,QAAuB,eAAvB;AAEA,MAAM;AAAEC,EAAAA;AAAF,IAAuBD,MAAM,CAAEd,WAAF,CAAnC;AACA,MAAM;AAAEgB,EAAAA;AAAF,IAAiBF,MAAM,CAAEJ,iBAAF,CAA7B;AAEA,MAAMO,KAAK,GAAG;AACbX,EAAAA,IADa;AAEbC,EAAAA,IAFa;AAGbW,EAAAA,WAAW,EAAEV,MAHA;AAIbW,EAAAA,gBAAgB,EAAEV;AAJL,CAAd;;AAOA,MAAMW,qCAAqC,GAAKC,QAAF,IAC7C,SAASC,0BAAT,OAAkD;AAAA,MAAb;AAAEC,IAAAA;AAAF,GAAa;AACjD,QAAMC,OAAO,GAAGR,UAAU,EAA1B;AACA,QAAMS,cAAc,GAAG,CAAE,CAAE,aAAF,EAAiB,kBAAjB,EAAsCC,QAAtC,CACxBL,QADwB,CAAzB;AAGA,QAAMM,IAAI,GAAGF,cAAc,GAAG,CAAEF,MAAF,CAAH,GAAgB,EAA3C;AACA,QAAM;AAAEK,IAAAA,OAAF;AAAWC,IAAAA;AAAX,MAAyB1B,SAAS,CAAI2B,MAAF,IAAc;AACvD,UAAM;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AAE,OAAF,CAFQ;AAGjBiE,IAAAA,IAAI,EAAEN;AAHW,GAAF,CAAhB;AAKA7C,EAAAA,gBAAgB,CAAE;AACjBgC,IAAAA,IAAI,EAAE,+BADW;AAEjBkB,IAAAA,KAAK,EAAEhE,EAAE,CAAE,OAAF,CAFQ;AAGjBiE,IAAAA,IAAI,EAAEL;AAHW,GAAF,CAAhB;AAKA9C,EAAAA,gBAAgB,CAAE;AACjBgC,IAAAA,IAAI,EAAE,mCADW;AAEjBkB,IAAAA,KAAK,EAAEhE,EAAE,CAAE,WAAF,CAFQ;AAGjBiE,IAAAA,IAAI,EAAEJ;AAHW,GAAF,CAAhB;AAKA/C,EAAAA,gBAAgB,CAAE;AACjBgC,IAAAA,IAAI,EAAE,wCADW;AAEjBkB,IAAAA,KAAK,EAAEhE,EAAE,CAAE,gBAAF,CAFQ;AAGjBiE,IAAAA,IAAI,EAAEH;AAHW,GAAF,CAAhB;AAKA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { privateApis } from '@wordpress/commands';\nimport { __ } from '@wordpress/i18n';\nimport { useMemo } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { post, page, layout, symbolFilled } from '@wordpress/icons';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { getQueryArg, addQueryArgs, getPath } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from './lock-unlock';\n\nconst { useCommandLoader } = unlock( privateApis );\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 deps = supportsSearch ? [ search ] : [];\n\t\tconst { records, isLoading } = useSelect( ( select ) => {\n\t\t\tconst { getEntityRecords } = select( coreStore );\n\t\t\tconst query = supportsSearch\n\t\t\t\t? {\n\t\t\t\t\t\tsearch: !! search ? search : undefined,\n\t\t\t\t\t\tper_page: 10,\n\t\t\t\t\t\torderby: search ? 'relevance' : 'date',\n\t\t\t\t }\n\t\t\t\t: {\n\t\t\t\t\t\tper_page: -1,\n\t\t\t\t };\n\t\t\treturn {\n\t\t\t\trecords: getEntityRecords( 'postType', postType, query ),\n\t\t\t\tisLoading: ! select( coreStore ).hasFinishedResolution(\n\t\t\t\t\t'getEntityRecords',\n\t\t\t\t\t[ 'postType', postType, query ]\n\t\t\t\t),\n\t\t\t\t// We're using the string literal to check whether we're in the site editor.\n\t\t\t\t/* eslint-disable-next-line @wordpress/data-no-store-string-literals */\n\t\t\t\tisSiteEditor: !! select( 'edit-site' ),\n\t\t\t};\n\t\t}, deps );\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: record.title?.rendered + ' ' + record.id,\n\t\t\t\t\tlabel: record.title?.rendered\n\t\t\t\t\t\t? record.title?.rendered\n\t\t\t\t\t\t: __( '(no title)' ),\n\t\t\t\t\ticon: icons[ postType ],\n\t\t\t\t\tcallback: ( { close } ) => {\n\t\t\t\t\t\tconst args = {\n\t\t\t\t\t\t\tpostType,\n\t\t\t\t\t\t\tpostId: record.id,\n\t\t\t\t\t\t\t...extraArgs,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tconst targetUrl = addQueryArgs(\n\t\t\t\t\t\t\t'site-editor.php',\n\t\t\t\t\t\t\targs\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\t\t\thistory.push( args );\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tclose();\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t} );\n\t\t}, [ records, history ] );\n\n\t\treturn {\n\t\t\tcommands,\n\t\t\tisLoading,\n\t\t};\n\t};\n\nconst usePageNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'page' );\nconst usePostNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'post' );\nconst useTemplateNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'wp_template' );\nconst useTemplatePartNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'wp_template_part' );\n\nexport function useSiteEditorNavigationCommands() {\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-pages',\n\t\tgroup: __( 'Pages' ),\n\t\thook: usePageNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-posts',\n\t\tgroup: __( 'Posts' ),\n\t\thook: usePostNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-templates',\n\t\tgroup: __( 'Templates' ),\n\t\thook: useTemplateNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-template-parts',\n\t\tgroup: __( 'Template Parts' ),\n\t\thook: useTemplatePartNavigationCommandLoader,\n\t} );\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wordpress/core-commands",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "WordPress core reusable commands.",
|
|
5
|
+
"author": "The WordPress Contributors",
|
|
6
|
+
"license": "GPL-2.0-or-later",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"wordpress",
|
|
9
|
+
"gutenberg",
|
|
10
|
+
"commands"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/WordPress/gutenberg/tree/HEAD/packages/core-commands/README.md",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/WordPress/gutenberg.git",
|
|
16
|
+
"directory": "packages/core-commands"
|
|
17
|
+
},
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/WordPress/gutenberg/issues"
|
|
20
|
+
},
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=12"
|
|
23
|
+
},
|
|
24
|
+
"main": "build/index.js",
|
|
25
|
+
"module": "build-module/index.js",
|
|
26
|
+
"react-native": "src/index",
|
|
27
|
+
"sideEffects": false,
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@babel/runtime": "^7.16.0",
|
|
30
|
+
"@wordpress/commands": "^0.4.0",
|
|
31
|
+
"@wordpress/core-data": "^6.10.0",
|
|
32
|
+
"@wordpress/data": "^9.3.0",
|
|
33
|
+
"@wordpress/element": "^5.10.0",
|
|
34
|
+
"@wordpress/i18n": "^4.33.0",
|
|
35
|
+
"@wordpress/icons": "^9.24.0",
|
|
36
|
+
"@wordpress/private-apis": "^0.15.0",
|
|
37
|
+
"@wordpress/router": "^0.2.0",
|
|
38
|
+
"@wordpress/url": "^3.34.0"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"react": "^18.0.0"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
},
|
|
46
|
+
"gitHead": "e936127e1e13881f1a940b7bd1593a9e500147f3"
|
|
47
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { privateApis } from '@wordpress/commands';
|
|
5
|
+
import { __ } from '@wordpress/i18n';
|
|
6
|
+
import { plus } from '@wordpress/icons';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Internal dependencies
|
|
10
|
+
*/
|
|
11
|
+
import { unlock } from './lock-unlock';
|
|
12
|
+
|
|
13
|
+
const { useCommand } = unlock( privateApis );
|
|
14
|
+
|
|
15
|
+
export function useAddPostTypeCommands() {
|
|
16
|
+
useCommand( {
|
|
17
|
+
name: 'add new post',
|
|
18
|
+
label: __( 'Add new post' ),
|
|
19
|
+
icon: plus,
|
|
20
|
+
callback: () => {
|
|
21
|
+
document.location.href = 'post-new.php';
|
|
22
|
+
},
|
|
23
|
+
} );
|
|
24
|
+
useCommand( {
|
|
25
|
+
name: 'add new page',
|
|
26
|
+
label: __( 'Add new page' ),
|
|
27
|
+
icon: plus,
|
|
28
|
+
callback: () => {
|
|
29
|
+
document.location.href = 'post-new.php?post_type=page';
|
|
30
|
+
},
|
|
31
|
+
} );
|
|
32
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { privateApis } from './private-apis';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';
|
|
5
|
+
|
|
6
|
+
export const { lock, unlock } =
|
|
7
|
+
__dangerousOptInToUnstableAPIsOnlyForCoreModules(
|
|
8
|
+
'I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.',
|
|
9
|
+
'@wordpress/core-commands'
|
|
10
|
+
);
|