@wordpress/edit-post 8.27.0 → 8.28.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/components/browser-url/index.js +32 -59
- package/build/components/browser-url/index.js.map +1 -1
- package/build-module/components/browser-url/index.js +33 -59
- package/build-module/components/browser-url/index.js.map +1 -1
- package/build-style/style-rtl.css +3 -19
- package/build-style/style.css +3 -19
- package/package.json +31 -31
- package/src/components/browser-url/index.js +29 -59
- package/src/components/browser-url/test/index.js +45 -15
- package/src/style.scss +0 -6
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default =
|
|
6
|
+
exports.default = BrowserURL;
|
|
7
7
|
exports.getPostEditURL = getPostEditURL;
|
|
8
8
|
var _element = require("@wordpress/element");
|
|
9
9
|
var _data = require("@wordpress/data");
|
|
@@ -26,65 +26,38 @@ function getPostEditURL(postId) {
|
|
|
26
26
|
action: 'edit'
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
componentDidUpdate(prevProps) {
|
|
37
|
-
const {
|
|
38
|
-
postId,
|
|
39
|
-
postStatus
|
|
40
|
-
} = this.props;
|
|
29
|
+
function BrowserURL() {
|
|
30
|
+
const [historyId, setHistoryId] = (0, _element.useState)(null);
|
|
31
|
+
const {
|
|
32
|
+
postId,
|
|
33
|
+
postStatus
|
|
34
|
+
} = (0, _data.useSelect)(select => {
|
|
41
35
|
const {
|
|
42
|
-
|
|
43
|
-
} =
|
|
44
|
-
|
|
45
|
-
|
|
36
|
+
getCurrentPost
|
|
37
|
+
} = select(_editor.store);
|
|
38
|
+
const post = getCurrentPost();
|
|
39
|
+
let {
|
|
40
|
+
id,
|
|
41
|
+
status,
|
|
42
|
+
type
|
|
43
|
+
} = post;
|
|
44
|
+
const isTemplate = ['wp_template', 'wp_template_part'].includes(type);
|
|
45
|
+
if (isTemplate) {
|
|
46
|
+
id = post.wp_id;
|
|
46
47
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}, 'Post ' + postId, getPostEditURL(postId));
|
|
62
|
-
this.setState(() => ({
|
|
63
|
-
historyId: postId
|
|
64
|
-
}));
|
|
65
|
-
}
|
|
66
|
-
render() {
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
48
|
+
return {
|
|
49
|
+
postId: id,
|
|
50
|
+
postStatus: status
|
|
51
|
+
};
|
|
52
|
+
}, []);
|
|
53
|
+
(0, _element.useEffect)(() => {
|
|
54
|
+
if (postId && postId !== historyId && postStatus !== 'auto-draft') {
|
|
55
|
+
window.history.replaceState({
|
|
56
|
+
id: postId
|
|
57
|
+
}, 'Post ' + postId, getPostEditURL(postId));
|
|
58
|
+
setHistoryId(postId);
|
|
59
|
+
}
|
|
60
|
+
}, [postId, postStatus, historyId]);
|
|
61
|
+
return null;
|
|
69
62
|
}
|
|
70
|
-
exports.BrowserURL = BrowserURL;
|
|
71
|
-
var _default = exports.default = (0, _data.withSelect)(select => {
|
|
72
|
-
const {
|
|
73
|
-
getCurrentPost
|
|
74
|
-
} = select(_editor.store);
|
|
75
|
-
const post = getCurrentPost();
|
|
76
|
-
let {
|
|
77
|
-
id,
|
|
78
|
-
status,
|
|
79
|
-
type
|
|
80
|
-
} = post;
|
|
81
|
-
const isTemplate = ['wp_template', 'wp_template_part'].includes(type);
|
|
82
|
-
if (isTemplate) {
|
|
83
|
-
id = post.wp_id;
|
|
84
|
-
}
|
|
85
|
-
return {
|
|
86
|
-
postId: id,
|
|
87
|
-
postStatus: status
|
|
88
|
-
};
|
|
89
|
-
})(BrowserURL);
|
|
90
63
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_element","require","_data","_url","_editor","getPostEditURL","postId","addQueryArgs","post","action","BrowserURL","
|
|
1
|
+
{"version":3,"names":["_element","require","_data","_url","_editor","getPostEditURL","postId","addQueryArgs","post","action","BrowserURL","historyId","setHistoryId","useState","postStatus","useSelect","select","getCurrentPost","editorStore","id","status","type","isTemplate","includes","wp_id","useEffect","window","history","replaceState"],"sources":["@wordpress/edit-post/src/components/browser-url/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect, useState } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { addQueryArgs } from '@wordpress/url';\nimport { store as editorStore } from '@wordpress/editor';\n\n/**\n * Returns the Post's Edit URL.\n *\n * @param {number} postId Post ID.\n *\n * @return {string} Post edit URL.\n */\nexport function getPostEditURL( postId ) {\n\treturn addQueryArgs( 'post.php', { post: postId, action: 'edit' } );\n}\n\nexport default function BrowserURL() {\n\tconst [ historyId, setHistoryId ] = useState( null );\n\tconst { postId, postStatus } = useSelect( ( select ) => {\n\t\tconst { getCurrentPost } = select( editorStore );\n\t\tconst post = getCurrentPost();\n\t\tlet { id, status, type } = post;\n\t\tconst isTemplate = [ 'wp_template', 'wp_template_part' ].includes(\n\t\t\ttype\n\t\t);\n\t\tif ( isTemplate ) {\n\t\t\tid = post.wp_id;\n\t\t}\n\n\t\treturn {\n\t\t\tpostId: id,\n\t\t\tpostStatus: status,\n\t\t};\n\t}, [] );\n\n\tuseEffect( () => {\n\t\tif ( postId && postId !== historyId && postStatus !== 'auto-draft' ) {\n\t\t\twindow.history.replaceState(\n\t\t\t\t{ id: postId },\n\t\t\t\t'Post ' + postId,\n\t\t\t\tgetPostEditURL( postId )\n\t\t\t);\n\t\t\tsetHistoryId( postId );\n\t\t}\n\t}, [ postId, post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AAc,CAAEC,MAAO,CACxB,CAAC;MACDM,YAAY,CAAEN,MAAO,CAAC;IACvB;EACD,CAAC,EAAE,CAAEA,MAAM,EAAEQ,UAAU,EAAEH,SAAS,CAAG,CAAC;EAEtC,OAAO,IAAI;AACZ","ignoreList":[]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { useEffect, useState } from '@wordpress/element';
|
|
5
|
+
import { useSelect } from '@wordpress/data';
|
|
6
6
|
import { addQueryArgs } from '@wordpress/url';
|
|
7
7
|
import { store as editorStore } from '@wordpress/editor';
|
|
8
8
|
|
|
@@ -19,64 +19,38 @@ export function getPostEditURL(postId) {
|
|
|
19
19
|
action: 'edit'
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
componentDidUpdate(prevProps) {
|
|
30
|
-
const {
|
|
31
|
-
postId,
|
|
32
|
-
postStatus
|
|
33
|
-
} = this.props;
|
|
22
|
+
export default function BrowserURL() {
|
|
23
|
+
const [historyId, setHistoryId] = useState(null);
|
|
24
|
+
const {
|
|
25
|
+
postId,
|
|
26
|
+
postStatus
|
|
27
|
+
} = useSelect(select => {
|
|
34
28
|
const {
|
|
35
|
-
|
|
36
|
-
} =
|
|
37
|
-
|
|
38
|
-
|
|
29
|
+
getCurrentPost
|
|
30
|
+
} = select(editorStore);
|
|
31
|
+
const post = getCurrentPost();
|
|
32
|
+
let {
|
|
33
|
+
id,
|
|
34
|
+
status,
|
|
35
|
+
type
|
|
36
|
+
} = post;
|
|
37
|
+
const isTemplate = ['wp_template', 'wp_template_part'].includes(type);
|
|
38
|
+
if (isTemplate) {
|
|
39
|
+
id = post.wp_id;
|
|
39
40
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}, 'Post ' + postId, getPostEditURL(postId));
|
|
55
|
-
this.setState(() => ({
|
|
56
|
-
historyId: postId
|
|
57
|
-
}));
|
|
58
|
-
}
|
|
59
|
-
render() {
|
|
60
|
-
return null;
|
|
61
|
-
}
|
|
41
|
+
return {
|
|
42
|
+
postId: id,
|
|
43
|
+
postStatus: status
|
|
44
|
+
};
|
|
45
|
+
}, []);
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (postId && postId !== historyId && postStatus !== 'auto-draft') {
|
|
48
|
+
window.history.replaceState({
|
|
49
|
+
id: postId
|
|
50
|
+
}, 'Post ' + postId, getPostEditURL(postId));
|
|
51
|
+
setHistoryId(postId);
|
|
52
|
+
}
|
|
53
|
+
}, [postId, postStatus, historyId]);
|
|
54
|
+
return null;
|
|
62
55
|
}
|
|
63
|
-
export default withSelect(select => {
|
|
64
|
-
const {
|
|
65
|
-
getCurrentPost
|
|
66
|
-
} = select(editorStore);
|
|
67
|
-
const post = getCurrentPost();
|
|
68
|
-
let {
|
|
69
|
-
id,
|
|
70
|
-
status,
|
|
71
|
-
type
|
|
72
|
-
} = post;
|
|
73
|
-
const isTemplate = ['wp_template', 'wp_template_part'].includes(type);
|
|
74
|
-
if (isTemplate) {
|
|
75
|
-
id = post.wp_id;
|
|
76
|
-
}
|
|
77
|
-
return {
|
|
78
|
-
postId: id,
|
|
79
|
-
postStatus: status
|
|
80
|
-
};
|
|
81
|
-
})(BrowserURL);
|
|
82
56
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["useEffect","useState","useSelect","addQueryArgs","store","editorStore","getPostEditURL","postId","post","action","BrowserURL","historyId","setHistoryId","postStatus","select","getCurrentPost","id","status","type","isTemplate","includes","wp_id","window","history","replaceState"],"sources":["@wordpress/edit-post/src/components/browser-url/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect, useState } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { addQueryArgs } from '@wordpress/url';\nimport { store as editorStore } from '@wordpress/editor';\n\n/**\n * Returns the Post's Edit URL.\n *\n * @param {number} postId Post ID.\n *\n * @return {string} Post edit URL.\n */\nexport function getPostEditURL( postId ) {\n\treturn addQueryArgs( 'post.php', { post: postId, action: 'edit' } );\n}\n\nexport default function BrowserURL() {\n\tconst [ historyId, setHistoryId ] = useState( null );\n\tconst { postId, postStatus } = useSelect( ( select ) => {\n\t\tconst { getCurrentPost } = select( editorStore );\n\t\tconst post = getCurrentPost();\n\t\tlet { id, status, type } = post;\n\t\tconst isTemplate = [ 'wp_template', 'wp_template_part' ].includes(\n\t\t\ttype\n\t\t);\n\t\tif ( isTemplate ) {\n\t\t\tid = post.wp_id;\n\t\t}\n\n\t\treturn {\n\t\t\tpostId: id,\n\t\t\tpostStatus: status,\n\t\t};\n\t}, [] );\n\n\tuseEffect( () => {\n\t\tif ( postId && postId !== historyId && postStatus !== 'auto-draft' ) {\n\t\t\twindow.history.replaceState(\n\t\t\t\t{ id: postId },\n\t\t\t\t'Post ' + postId,\n\t\t\t\tgetPostEditURL( postId )\n\t\t\t);\n\t\t\tsetHistoryId( postId );\n\t\t}\n\t}, [ postId, postStatus, historyId ] );\n\n\treturn null;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,EAAEC,QAAQ,QAAQ,oBAAoB;AACxD,SAASC,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,YAAY,QAAQ,gBAAgB;AAC7C,SAASC,KAAK,IAAIC,WAAW,QAAQ,mBAAmB;;AAExD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,cAAcA,CAAEC,MAAM,EAAG;EACxC,OAAOJ,YAAY,CAAE,UA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|
|
250
|
+
width: 64px;
|
|
251
251
|
position: relative;
|
|
252
252
|
}
|
|
253
253
|
.edit-post-fullscreen-mode-close.components-button:active {
|
|
@@ -300,7 +300,7 @@
|
|
|
300
300
|
* Show icon label overrides.
|
|
301
301
|
*/
|
|
302
302
|
.show-icon-labels .editor-header .edit-post-fullscreen-mode-close.has-icon {
|
|
303
|
-
width:
|
|
303
|
+
width: 64px;
|
|
304
304
|
}
|
|
305
305
|
.show-icon-labels .editor-header .edit-post-fullscreen-mode-close.has-icon svg {
|
|
306
306
|
display: block;
|
|
@@ -623,25 +623,9 @@ body.js.block-editor-page .media-frame select.attachment-filters:last-of-type {
|
|
|
623
623
|
}
|
|
624
624
|
}
|
|
625
625
|
|
|
626
|
-
.editor-header,
|
|
627
|
-
.editor-text-editor,
|
|
628
|
-
.editor-sidebar,
|
|
629
|
-
.editor-post-publish-panel,
|
|
630
626
|
.edit-post-visual-editor.is-iframed {
|
|
631
627
|
box-sizing: border-box;
|
|
632
628
|
}
|
|
633
|
-
.editor-header *,
|
|
634
|
-
.editor-header *::before,
|
|
635
|
-
.editor-header *::after,
|
|
636
|
-
.editor-text-editor *,
|
|
637
|
-
.editor-text-editor *::before,
|
|
638
|
-
.editor-text-editor *::after,
|
|
639
|
-
.editor-sidebar *,
|
|
640
|
-
.editor-sidebar *::before,
|
|
641
|
-
.editor-sidebar *::after,
|
|
642
|
-
.editor-post-publish-panel *,
|
|
643
|
-
.editor-post-publish-panel *::before,
|
|
644
|
-
.editor-post-publish-panel *::after,
|
|
645
629
|
.edit-post-visual-editor.is-iframed *,
|
|
646
630
|
.edit-post-visual-editor.is-iframed *::before,
|
|
647
631
|
.edit-post-visual-editor.is-iframed *::after {
|
package/build-style/style.css
CHANGED
|
@@ -246,8 +246,8 @@
|
|
|
246
246
|
background: #1e1e1e;
|
|
247
247
|
color: #fff;
|
|
248
248
|
border-radius: 0;
|
|
249
|
-
height:
|
|
250
|
-
width:
|
|
249
|
+
height: 64px;
|
|
250
|
+
width: 64px;
|
|
251
251
|
position: relative;
|
|
252
252
|
}
|
|
253
253
|
.edit-post-fullscreen-mode-close.components-button:active {
|
|
@@ -300,7 +300,7 @@
|
|
|
300
300
|
* Show icon label overrides.
|
|
301
301
|
*/
|
|
302
302
|
.show-icon-labels .editor-header .edit-post-fullscreen-mode-close.has-icon {
|
|
303
|
-
width:
|
|
303
|
+
width: 64px;
|
|
304
304
|
}
|
|
305
305
|
.show-icon-labels .editor-header .edit-post-fullscreen-mode-close.has-icon svg {
|
|
306
306
|
display: block;
|
|
@@ -623,25 +623,9 @@ body.js.block-editor-page .media-frame select.attachment-filters:last-of-type {
|
|
|
623
623
|
}
|
|
624
624
|
}
|
|
625
625
|
|
|
626
|
-
.editor-header,
|
|
627
|
-
.editor-text-editor,
|
|
628
|
-
.editor-sidebar,
|
|
629
|
-
.editor-post-publish-panel,
|
|
630
626
|
.edit-post-visual-editor.is-iframed {
|
|
631
627
|
box-sizing: border-box;
|
|
632
628
|
}
|
|
633
|
-
.editor-header *,
|
|
634
|
-
.editor-header *::before,
|
|
635
|
-
.editor-header *::after,
|
|
636
|
-
.editor-text-editor *,
|
|
637
|
-
.editor-text-editor *::before,
|
|
638
|
-
.editor-text-editor *::after,
|
|
639
|
-
.editor-sidebar *,
|
|
640
|
-
.editor-sidebar *::before,
|
|
641
|
-
.editor-sidebar *::after,
|
|
642
|
-
.editor-post-publish-panel *,
|
|
643
|
-
.editor-post-publish-panel *::before,
|
|
644
|
-
.editor-post-publish-panel *::after,
|
|
645
629
|
.edit-post-visual-editor.is-iframed *,
|
|
646
630
|
.edit-post-visual-editor.is-iframed *::before,
|
|
647
631
|
.edit-post-visual-editor.is-iframed *::after {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/edit-post",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.28.0",
|
|
4
4
|
"description": "Edit Post module for WordPress.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -29,35 +29,35 @@
|
|
|
29
29
|
"wpScript": true,
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@babel/runtime": "7.25.7",
|
|
32
|
-
"@wordpress/a11y": "^4.
|
|
33
|
-
"@wordpress/api-fetch": "^7.
|
|
34
|
-
"@wordpress/block-editor": "^15.
|
|
35
|
-
"@wordpress/block-library": "^9.
|
|
36
|
-
"@wordpress/blocks": "^15.
|
|
37
|
-
"@wordpress/commands": "^1.
|
|
38
|
-
"@wordpress/components": "^30.
|
|
39
|
-
"@wordpress/compose": "^7.
|
|
40
|
-
"@wordpress/core-commands": "^1.
|
|
41
|
-
"@wordpress/core-data": "^7.
|
|
42
|
-
"@wordpress/data": "^10.
|
|
43
|
-
"@wordpress/deprecated": "^4.
|
|
44
|
-
"@wordpress/dom": "^4.
|
|
45
|
-
"@wordpress/editor": "^14.
|
|
46
|
-
"@wordpress/element": "^6.
|
|
47
|
-
"@wordpress/hooks": "^4.
|
|
48
|
-
"@wordpress/html-entities": "^4.
|
|
49
|
-
"@wordpress/i18n": "^6.
|
|
50
|
-
"@wordpress/icons": "^10.
|
|
51
|
-
"@wordpress/keyboard-shortcuts": "^5.
|
|
52
|
-
"@wordpress/keycodes": "^4.
|
|
53
|
-
"@wordpress/notices": "^5.
|
|
54
|
-
"@wordpress/plugins": "^7.
|
|
55
|
-
"@wordpress/preferences": "^4.
|
|
56
|
-
"@wordpress/private-apis": "^1.
|
|
57
|
-
"@wordpress/url": "^4.
|
|
58
|
-
"@wordpress/viewport": "^6.
|
|
59
|
-
"@wordpress/warning": "^3.
|
|
60
|
-
"@wordpress/widgets": "^4.
|
|
32
|
+
"@wordpress/a11y": "^4.28.0",
|
|
33
|
+
"@wordpress/api-fetch": "^7.28.0",
|
|
34
|
+
"@wordpress/block-editor": "^15.1.0",
|
|
35
|
+
"@wordpress/block-library": "^9.28.0",
|
|
36
|
+
"@wordpress/blocks": "^15.1.0",
|
|
37
|
+
"@wordpress/commands": "^1.28.0",
|
|
38
|
+
"@wordpress/components": "^30.1.0",
|
|
39
|
+
"@wordpress/compose": "^7.28.0",
|
|
40
|
+
"@wordpress/core-commands": "^1.28.0",
|
|
41
|
+
"@wordpress/core-data": "^7.28.0",
|
|
42
|
+
"@wordpress/data": "^10.28.0",
|
|
43
|
+
"@wordpress/deprecated": "^4.28.0",
|
|
44
|
+
"@wordpress/dom": "^4.28.0",
|
|
45
|
+
"@wordpress/editor": "^14.28.0",
|
|
46
|
+
"@wordpress/element": "^6.28.0",
|
|
47
|
+
"@wordpress/hooks": "^4.28.0",
|
|
48
|
+
"@wordpress/html-entities": "^4.28.0",
|
|
49
|
+
"@wordpress/i18n": "^6.1.0",
|
|
50
|
+
"@wordpress/icons": "^10.28.0",
|
|
51
|
+
"@wordpress/keyboard-shortcuts": "^5.28.0",
|
|
52
|
+
"@wordpress/keycodes": "^4.28.0",
|
|
53
|
+
"@wordpress/notices": "^5.28.0",
|
|
54
|
+
"@wordpress/plugins": "^7.28.0",
|
|
55
|
+
"@wordpress/preferences": "^4.28.0",
|
|
56
|
+
"@wordpress/private-apis": "^1.28.0",
|
|
57
|
+
"@wordpress/url": "^4.28.0",
|
|
58
|
+
"@wordpress/viewport": "^6.28.0",
|
|
59
|
+
"@wordpress/warning": "^3.28.0",
|
|
60
|
+
"@wordpress/widgets": "^4.28.0",
|
|
61
61
|
"clsx": "^2.1.1",
|
|
62
62
|
"memize": "^2.1.0"
|
|
63
63
|
},
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
"publishConfig": {
|
|
69
69
|
"access": "public"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "28cc2098f5ee28f89096b638533796538f495f72"
|
|
72
72
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { useEffect, useState } from '@wordpress/element';
|
|
5
|
+
import { useSelect } from '@wordpress/data';
|
|
6
6
|
import { addQueryArgs } from '@wordpress/url';
|
|
7
7
|
import { store as editorStore } from '@wordpress/editor';
|
|
8
8
|
|
|
@@ -17,65 +17,35 @@ export function getPostEditURL( postId ) {
|
|
|
17
17
|
return addQueryArgs( 'post.php', { post: postId, action: 'edit' } );
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
export default function BrowserURL() {
|
|
21
|
+
const [ historyId, setHistoryId ] = useState( null );
|
|
22
|
+
const { postId, postStatus } = useSelect( ( select ) => {
|
|
23
|
+
const { getCurrentPost } = select( editorStore );
|
|
24
|
+
const post = getCurrentPost();
|
|
25
|
+
let { id, status, type } = post;
|
|
26
|
+
const isTemplate = [ 'wp_template', 'wp_template_part' ].includes(
|
|
27
|
+
type
|
|
28
|
+
);
|
|
29
|
+
if ( isTemplate ) {
|
|
30
|
+
id = post.wp_id;
|
|
31
|
+
}
|
|
23
32
|
|
|
24
|
-
|
|
25
|
-
|
|
33
|
+
return {
|
|
34
|
+
postId: id,
|
|
35
|
+
postStatus: status,
|
|
26
36
|
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
postId
|
|
37
|
-
) {
|
|
38
|
-
this.setBrowserURL( postId );
|
|
37
|
+
}, [] );
|
|
38
|
+
|
|
39
|
+
useEffect( () => {
|
|
40
|
+
if ( postId && postId !== historyId && postStatus !== 'auto-draft' ) {
|
|
41
|
+
window.history.replaceState(
|
|
42
|
+
{ id: postId },
|
|
43
|
+
'Post ' + postId,
|
|
44
|
+
getPostEditURL( postId )
|
|
45
|
+
);
|
|
46
|
+
setHistoryId( postId );
|
|
39
47
|
}
|
|
40
|
-
}
|
|
48
|
+
}, [ postId, postStatus, historyId ] );
|
|
41
49
|
|
|
42
|
-
|
|
43
|
-
* Replaces the browser URL with a post editor link for the given post ID.
|
|
44
|
-
*
|
|
45
|
-
* Note it is important that, since this function may be called when the
|
|
46
|
-
* editor first loads, the result generated `getPostEditURL` matches that
|
|
47
|
-
* produced by the server. Otherwise, the URL will change unexpectedly.
|
|
48
|
-
*
|
|
49
|
-
* @param {number} postId Post ID for which to generate post editor URL.
|
|
50
|
-
*/
|
|
51
|
-
setBrowserURL( postId ) {
|
|
52
|
-
window.history.replaceState(
|
|
53
|
-
{ id: postId },
|
|
54
|
-
'Post ' + postId,
|
|
55
|
-
getPostEditURL( postId )
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
this.setState( () => ( {
|
|
59
|
-
historyId: postId,
|
|
60
|
-
} ) );
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
render() {
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
50
|
+
return null;
|
|
66
51
|
}
|
|
67
|
-
|
|
68
|
-
export default withSelect( ( select ) => {
|
|
69
|
-
const { getCurrentPost } = select( editorStore );
|
|
70
|
-
const post = getCurrentPost();
|
|
71
|
-
let { id, status, type } = post;
|
|
72
|
-
const isTemplate = [ 'wp_template', 'wp_template_part' ].includes( type );
|
|
73
|
-
if ( isTemplate ) {
|
|
74
|
-
id = post.wp_id;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return {
|
|
78
|
-
postId: id,
|
|
79
|
-
postStatus: status,
|
|
80
|
-
};
|
|
81
|
-
} )( BrowserURL );
|
|
@@ -3,10 +3,26 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { render } from '@testing-library/react';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { useSelect } from '@wordpress/data';
|
|
10
|
+
|
|
6
11
|
/**
|
|
7
12
|
* Internal dependencies
|
|
8
13
|
*/
|
|
9
|
-
import {
|
|
14
|
+
import { default as BrowserURL, getPostEditURL } from '../';
|
|
15
|
+
|
|
16
|
+
jest.mock( '@wordpress/data/src/components/use-select', () => jest.fn() );
|
|
17
|
+
|
|
18
|
+
function setupUseSelectMock( { postId, postStatus } ) {
|
|
19
|
+
useSelect.mockImplementation( () => {
|
|
20
|
+
return {
|
|
21
|
+
postId,
|
|
22
|
+
postStatus,
|
|
23
|
+
};
|
|
24
|
+
} );
|
|
25
|
+
}
|
|
10
26
|
|
|
11
27
|
describe( 'getPostEditURL', () => {
|
|
12
28
|
it( 'should generate relative path with post and action arguments', () => {
|
|
@@ -32,20 +48,28 @@ describe( 'BrowserURL', () => {
|
|
|
32
48
|
} );
|
|
33
49
|
|
|
34
50
|
it( 'not update URL if post is auto-draft', () => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
51
|
+
setupUseSelectMock( {
|
|
52
|
+
postId: 1,
|
|
53
|
+
postStatus: 'auto-draft',
|
|
54
|
+
} );
|
|
38
55
|
|
|
56
|
+
render( <BrowserURL /> );
|
|
39
57
|
expect( replaceStateSpy ).not.toHaveBeenCalled();
|
|
40
58
|
} );
|
|
41
59
|
|
|
42
60
|
it( 'update URL if post is no longer auto-draft', () => {
|
|
61
|
+
setupUseSelectMock( {
|
|
62
|
+
postId: 1,
|
|
63
|
+
postStatus: 'auto-draft',
|
|
64
|
+
} );
|
|
43
65
|
const { rerender } = render( <BrowserURL /> );
|
|
44
66
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
67
|
+
setupUseSelectMock( {
|
|
68
|
+
postId: 1,
|
|
69
|
+
postStatus: 'draft',
|
|
70
|
+
} );
|
|
48
71
|
|
|
72
|
+
rerender( <BrowserURL /> );
|
|
49
73
|
expect( replaceStateSpy ).toHaveBeenCalledWith(
|
|
50
74
|
{ id: 1 },
|
|
51
75
|
'Post 1',
|
|
@@ -54,26 +78,32 @@ describe( 'BrowserURL', () => {
|
|
|
54
78
|
} );
|
|
55
79
|
|
|
56
80
|
it( 'not update URL if history is already set', () => {
|
|
81
|
+
setupUseSelectMock( {
|
|
82
|
+
postId: 1,
|
|
83
|
+
postStatus: 'draft',
|
|
84
|
+
} );
|
|
57
85
|
const { rerender } = render( <BrowserURL /> );
|
|
58
86
|
|
|
59
|
-
rerender( <BrowserURL postId={ 1 } postStatus="draft" /> );
|
|
60
|
-
|
|
61
87
|
replaceStateSpy.mockReset();
|
|
62
88
|
|
|
63
|
-
rerender( <BrowserURL
|
|
64
|
-
|
|
89
|
+
rerender( <BrowserURL /> );
|
|
65
90
|
expect( replaceStateSpy ).not.toHaveBeenCalled();
|
|
66
91
|
} );
|
|
67
92
|
|
|
68
93
|
it( 'update URL if post ID changes', () => {
|
|
94
|
+
setupUseSelectMock( {
|
|
95
|
+
postId: 1,
|
|
96
|
+
postStatus: 'draft',
|
|
97
|
+
} );
|
|
69
98
|
const { rerender } = render( <BrowserURL /> );
|
|
70
99
|
|
|
71
|
-
|
|
72
|
-
|
|
100
|
+
setupUseSelectMock( {
|
|
101
|
+
postId: 2,
|
|
102
|
+
postStatus: 'draft',
|
|
103
|
+
} );
|
|
73
104
|
replaceStateSpy.mockReset();
|
|
74
105
|
|
|
75
|
-
rerender( <BrowserURL
|
|
76
|
-
|
|
106
|
+
rerender( <BrowserURL /> );
|
|
77
107
|
expect( replaceStateSpy ).toHaveBeenCalledWith(
|
|
78
108
|
{ id: 2 },
|
|
79
109
|
'Post 2',
|
package/src/style.scss
CHANGED
|
@@ -15,12 +15,6 @@ body.js.block-editor-page {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
// Target the editor UI excluding the non-iframed visual editor contents, metaboxes
|
|
19
|
-
// and custom fields areas.
|
|
20
|
-
.editor-header,
|
|
21
|
-
.editor-text-editor,
|
|
22
|
-
.editor-sidebar,
|
|
23
|
-
.editor-post-publish-panel,
|
|
24
18
|
.edit-post-visual-editor.is-iframed {
|
|
25
19
|
@include reset;
|
|
26
20
|
}
|