@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 CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 8.28.0 (2025-08-07)
6
+
5
7
  ## 8.27.0 (2025-07-23)
6
8
 
7
9
  ## 8.26.0 (2025-06-25)
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = exports.BrowserURL = void 0;
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
- class BrowserURL extends _element.Component {
30
- constructor() {
31
- super(...arguments);
32
- this.state = {
33
- historyId: null
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
- historyId
43
- } = this.state;
44
- if ((postId !== prevProps.postId || postId !== historyId) && postStatus !== 'auto-draft' && postId) {
45
- this.setBrowserURL(postId);
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
- * Replaces the browser URL with a post editor link for the given post ID.
51
- *
52
- * Note it is important that, since this function may be called when the
53
- * editor first loads, the result generated `getPostEditURL` matches that
54
- * produced by the server. Otherwise, the URL will change unexpectedly.
55
- *
56
- * @param {number} postId Post ID for which to generate post editor URL.
57
- */
58
- setBrowserURL(postId) {
59
- window.history.replaceState({
60
- id: postId
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","Component","constructor","arguments","state","historyId","componentDidUpdate","prevProps","postStatus","props","setBrowserURL","window","history","replaceState","id","setState","render","exports","_default","default","withSelect","select","getCurrentPost","editorStore","status","type","isTemplate","includes","wp_id"],"sources":["@wordpress/edit-post/src/components/browser-url/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { Component } from '@wordpress/element';\nimport { withSelect } 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 class BrowserURL extends Component {\n\tconstructor() {\n\t\tsuper( ...arguments );\n\n\t\tthis.state = {\n\t\t\thistoryId: null,\n\t\t};\n\t}\n\n\tcomponentDidUpdate( prevProps ) {\n\t\tconst { postId, postStatus } = this.props;\n\t\tconst { historyId } = this.state;\n\n\t\tif (\n\t\t\t( postId !== prevProps.postId || postId !== historyId ) &&\n\t\t\tpostStatus !== 'auto-draft' &&\n\t\t\tpostId\n\t\t) {\n\t\t\tthis.setBrowserURL( postId );\n\t\t}\n\t}\n\n\t/**\n\t * Replaces the browser URL with a post editor link for the given post ID.\n\t *\n\t * Note it is important that, since this function may be called when the\n\t * editor first loads, the result generated `getPostEditURL` matches that\n\t * produced by the server. Otherwise, the URL will change unexpectedly.\n\t *\n\t * @param {number} postId Post ID for which to generate post editor URL.\n\t */\n\tsetBrowserURL( postId ) {\n\t\twindow.history.replaceState(\n\t\t\t{ id: postId },\n\t\t\t'Post ' + postId,\n\t\t\tgetPostEditURL( postId )\n\t\t);\n\n\t\tthis.setState( () => ( {\n\t\t\thistoryId: postId,\n\t\t} ) );\n\t}\n\n\trender() {\n\t\treturn null;\n\t}\n}\n\nexport default withSelect( ( select ) => {\n\tconst { getCurrentPost } = select( editorStore );\n\tconst post = getCurrentPost();\n\tlet { id, status, type } = post;\n\tconst isTemplate = [ 'wp_template', 'wp_template_part' ].includes( type );\n\tif ( isTemplate ) {\n\t\tid = post.wp_id;\n\t}\n\n\treturn {\n\t\tpostId: id,\n\t\tpostStatus: status,\n\t};\n} )( BrowserURL );\n"],"mappings":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,IAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AANA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASI,cAAcA,CAAEC,MAAM,EAAG;EACxC,OAAO,IAAAC,iBAAY,E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;EAAK,CAAC,GAAG3B,IAAI;EAC/B,MAAM4B,UAAU,GAAG,CAAE,aAAa,EAAE,kBAAkB,CAAE,CAACC,QAAQ,CAAEF,IAAK,CAAC;EACzE,IAAKC,UAAU,EAAG;IACjBZ,EAAE,GAAGhB,IAAI,CAAC8B,KAAK;EAChB;EAEA,OAAO;IACNhC,MAAM,EAAEkB,EAAE;IACVN,UAAU,EAAEgB;EACb,CAAC;AACF,CAAE,CAAC,CAAExB,UAAW,CAAC","ignoreList":[]}
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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ACpEY,MAAM,CAACC,OAAO,CAACC,YAAY,CAC1B;QAAET,EAAE,EAAEb;MAAO,CAAC,EACd,OAAO,GAAGA,MAAM,EAChBD,cAAc,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 { Component } from '@wordpress/element';
5
- import { withSelect } from '@wordpress/data';
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 class BrowserURL extends Component {
23
- constructor() {
24
- super(...arguments);
25
- this.state = {
26
- historyId: null
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
- historyId
36
- } = this.state;
37
- if ((postId !== prevProps.postId || postId !== historyId) && postStatus !== 'auto-draft' && postId) {
38
- this.setBrowserURL(postId);
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
- * 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, 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":["Component","withSelect","addQueryArgs","store","editorStore","getPostEditURL","postId","post","action","BrowserURL","constructor","arguments","state","historyId","componentDidUpdate","prevProps","postStatus","props","setBrowserURL","window","history","replaceState","id","setState","render","select","getCurrentPost","status","type","isTemplate","includes","wp_id"],"sources":["@wordpress/edit-post/src/components/browser-url/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { Component } from '@wordpress/element';\nimport { withSelect } 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 class BrowserURL extends Component {\n\tconstructor() {\n\t\tsuper( ...arguments );\n\n\t\tthis.state = {\n\t\t\thistoryId: null,\n\t\t};\n\t}\n\n\tcomponentDidUpdate( prevProps ) {\n\t\tconst { postId, postStatus } = this.props;\n\t\tconst { historyId } = this.state;\n\n\t\tif (\n\t\t\t( postId !== prevProps.postId || postId !== historyId ) &&\n\t\t\tpostStatus !== 'auto-draft' &&\n\t\t\tpostId\n\t\t) {\n\t\t\tthis.setBrowserURL( postId );\n\t\t}\n\t}\n\n\t/**\n\t * Replaces the browser URL with a post editor link for the given post ID.\n\t *\n\t * Note it is important that, since this function may be called when the\n\t * editor first loads, the result generated `getPostEditURL` matches that\n\t * produced by the server. Otherwise, the URL will change unexpectedly.\n\t *\n\t * @param {number} postId Post ID for which to generate post editor URL.\n\t */\n\tsetBrowserURL( postId ) {\n\t\twindow.history.replaceState(\n\t\t\t{ id: postId },\n\t\t\t'Post ' + postId,\n\t\t\tgetPostEditURL( postId )\n\t\t);\n\n\t\tthis.setState( () => ( {\n\t\t\thistoryId: postId,\n\t\t} ) );\n\t}\n\n\trender() {\n\t\treturn null;\n\t}\n}\n\nexport default withSelect( ( select ) => {\n\tconst { getCurrentPost } = select( editorStore );\n\tconst post = getCurrentPost();\n\tlet { id, status, type } = post;\n\tconst isTemplate = [ 'wp_template', 'wp_template_part' ].includes( type );\n\tif ( isTemplate ) {\n\t\tid = post.wp_id;\n\t}\n\n\treturn {\n\t\tpostId: id,\n\t\tpostStatus: status,\n\t};\n} )( BrowserURL );\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,QAAQ,oBAAoB;AAC9C,SAASC,UAAU,QAAQ,iBAAiB;AAC5C,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,UAAU,EAAE;IAAEK,IAAI,EAAED,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CAAC;EACzE,IAAKC,UAAU,EAAG;IACjBP,EAAE,GAAGf,IAAI,CAACwB,KAAK;EAChB;EAEA,OAAO;IACNzB,MAAM,EAAEgB,EAAE;IACVN,UAAU,EAAEW;EACb,CAAC;AACF,CAAE,CAAC,CAAElB,UAAW,CAAC","ignoreList":[]}
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}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xB,CAAC;MACDK,YAAY,CAAEL,MAAO,CAAC;IACvB;EACD,CAAC,EAAE,CAAEA,MAAM,EAAEM,UAAU,EAAEF,SAAS,CAAG,CAAC;EAEtC,OAAO,IAAI;AACZ","ignoreList":[]}
@@ -246,8 +246,8 @@
246
246
  background: #1e1e1e;
247
247
  color: #fff;
248
248
  border-radius: 0;
249
- height: 60px;
250
- width: 60px;
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: 60px;
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 {
@@ -246,8 +246,8 @@
246
246
  background: #1e1e1e;
247
247
  color: #fff;
248
248
  border-radius: 0;
249
- height: 60px;
250
- width: 60px;
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: 60px;
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.27.0",
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.27.0",
33
- "@wordpress/api-fetch": "^7.27.0",
34
- "@wordpress/block-editor": "^15.0.0",
35
- "@wordpress/block-library": "^9.27.0",
36
- "@wordpress/blocks": "^15.0.0",
37
- "@wordpress/commands": "^1.27.0",
38
- "@wordpress/components": "^30.0.0",
39
- "@wordpress/compose": "^7.27.0",
40
- "@wordpress/core-commands": "^1.27.0",
41
- "@wordpress/core-data": "^7.27.0",
42
- "@wordpress/data": "^10.27.0",
43
- "@wordpress/deprecated": "^4.27.0",
44
- "@wordpress/dom": "^4.27.0",
45
- "@wordpress/editor": "^14.27.0",
46
- "@wordpress/element": "^6.27.0",
47
- "@wordpress/hooks": "^4.27.0",
48
- "@wordpress/html-entities": "^4.27.0",
49
- "@wordpress/i18n": "^6.0.0",
50
- "@wordpress/icons": "^10.27.0",
51
- "@wordpress/keyboard-shortcuts": "^5.27.0",
52
- "@wordpress/keycodes": "^4.27.0",
53
- "@wordpress/notices": "^5.27.0",
54
- "@wordpress/plugins": "^7.27.0",
55
- "@wordpress/preferences": "^4.27.0",
56
- "@wordpress/private-apis": "^1.27.0",
57
- "@wordpress/url": "^4.27.0",
58
- "@wordpress/viewport": "^6.27.0",
59
- "@wordpress/warning": "^3.27.0",
60
- "@wordpress/widgets": "^4.27.0",
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": "abe06a6f2aef8d03c30ea9d5b3e133f041e523b1"
71
+ "gitHead": "28cc2098f5ee28f89096b638533796538f495f72"
72
72
  }
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { Component } from '@wordpress/element';
5
- import { withSelect } from '@wordpress/data';
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 class BrowserURL extends Component {
21
- constructor() {
22
- super( ...arguments );
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
- this.state = {
25
- historyId: null,
33
+ return {
34
+ postId: id,
35
+ postStatus: status,
26
36
  };
27
- }
28
-
29
- componentDidUpdate( prevProps ) {
30
- const { postId, postStatus } = this.props;
31
- const { historyId } = this.state;
32
-
33
- if (
34
- ( postId !== prevProps.postId || postId !== historyId ) &&
35
- postStatus !== 'auto-draft' &&
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 { getPostEditURL, BrowserURL } from '../';
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
- const { rerender } = render( <BrowserURL /> );
36
-
37
- rerender( <BrowserURL postId={ 1 } postStatus="auto-draft" /> );
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
- rerender( <BrowserURL postId={ 1 } postStatus="auto-draft" /> );
46
-
47
- rerender( <BrowserURL postId={ 1 } postStatus="draft" /> );
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 postId={ 1 } postStatus="draft" /> );
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
- rerender( <BrowserURL postId={ 1 } postStatus="draft" /> );
72
-
100
+ setupUseSelectMock( {
101
+ postId: 2,
102
+ postStatus: 'draft',
103
+ } );
73
104
  replaceStateSpy.mockReset();
74
105
 
75
- rerender( <BrowserURL postId={ 2 } postStatus="draft" /> );
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
  }