@wordpress/edit-post 8.30.0 → 8.30.1-next.836ecdcae.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.
@@ -7,6 +7,7 @@ exports.useUpdatePostLinkListener = void 0;
7
7
  var _data = require("@wordpress/data");
8
8
  var _element = require("@wordpress/element");
9
9
  var _editor = require("@wordpress/editor");
10
+ var _coreData = require("@wordpress/core-data");
10
11
  var _constants = require("../../store/constants");
11
12
  /**
12
13
  * WordPress dependencies
@@ -22,10 +23,22 @@ var _constants = require("../../store/constants");
22
23
  */
23
24
  const useUpdatePostLinkListener = () => {
24
25
  const {
26
+ isViewable,
25
27
  newPermalink
26
- } = (0, _data.useSelect)(select => ({
27
- newPermalink: select(_editor.store).getCurrentPost().link
28
- }), []);
28
+ } = (0, _data.useSelect)(select => {
29
+ const {
30
+ getPostType
31
+ } = select(_coreData.store);
32
+ const {
33
+ getCurrentPost,
34
+ getEditedPostAttribute
35
+ } = select(_editor.store);
36
+ const postType = getPostType(getEditedPostAttribute('type'));
37
+ return {
38
+ isViewable: postType?.viewable,
39
+ newPermalink: getCurrentPost().link
40
+ };
41
+ }, []);
29
42
  const nodeToUpdateRef = (0, _element.useRef)();
30
43
  (0, _element.useEffect)(() => {
31
44
  nodeToUpdateRef.current = document.querySelector(_constants.VIEW_AS_PREVIEW_LINK_SELECTOR) || document.querySelector(_constants.VIEW_AS_LINK_SELECTOR);
@@ -34,8 +47,13 @@ const useUpdatePostLinkListener = () => {
34
47
  if (!newPermalink || !nodeToUpdateRef.current) {
35
48
  return;
36
49
  }
50
+ if (!isViewable) {
51
+ nodeToUpdateRef.current.style.display = 'none';
52
+ return;
53
+ }
54
+ nodeToUpdateRef.current.style.display = '';
37
55
  nodeToUpdateRef.current.setAttribute('href', newPermalink);
38
- }, [newPermalink]);
56
+ }, [newPermalink, isViewable]);
39
57
  };
40
58
  exports.useUpdatePostLinkListener = useUpdatePostLinkListener;
41
59
  //# sourceMappingURL=listener-hooks.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_data","require","_element","_editor","_constants","useUpdatePostLinkListener","newPermalink","useSelect","select","editorStore","getCurrentPost","link","nodeToUpdateRef","useRef","useEffect","current","document","querySelector","VIEW_AS_PREVIEW_LINK_SELECTOR","VIEW_AS_LINK_SELECTOR","setAttribute","exports"],"sources":["@wordpress/edit-post/src/components/editor-initialization/listener-hooks.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { useEffect, useRef } from '@wordpress/element';\nimport { store as editorStore } from '@wordpress/editor';\n\n/**\n * Internal dependencies\n */\nimport {\n\tVIEW_AS_LINK_SELECTOR,\n\tVIEW_AS_PREVIEW_LINK_SELECTOR,\n} from '../../store/constants';\n\n/**\n * This listener hook monitors any change in permalink and updates the view\n * post link in the admin bar.\n */\nexport const useUpdatePostLinkListener = () => {\n\tconst { newPermalink } = useSelect(\n\t\t( select ) => ( {\n\t\t\tnewPermalink: select( editorStore ).getCurrentPost().link,\n\t\t} ),\n\t\t[]\n\t);\n\tconst nodeToUpdateRef = useRef();\n\n\tuseEffect( () => {\n\t\tnodeToUpdateRef.current =\n\t\t\tdocument.querySelector( VIEW_AS_PREVIEW_LINK_SELECTOR ) ||\n\t\t\tdocument.querySelector( VIEW_AS_LINK_SELECTOR );\n\t}, [] );\n\n\tuseEffect( () => {\n\t\tif ( ! newPermalink || ! nodeToUpdateRef.current ) {\n\t\t\treturn;\n\t\t}\n\t\tnodeToUpdateRef.current.setAttribute( 'href', newPermalink );\n\t}, [ newPermalink ] );\n};\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AAKA,IAAAG,UAAA,GAAAH,OAAA;AAVA;AACA;AACA;;AAKA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACO,MAAMI,yBAAyB,GAAGA,CAAA,KAAM;EAC9C,MAAM;IAAEC;EAAa,CAAC,GAAG,IAAAC,eAAS,EAC/BC,MAAM,KAAQ;IACfF,YAAY,EAAEE,MAAM,CAAEC,aAAY,CAAC,CAACC,cAAc,CAAC,CAAC,CAACC;EACtD,CAAC,CAAE,EACH,EACD,CAAC;EACD,MAAMC,eAAe,GAAG,IAAAC,eAAM,EAAC,CAAC;EAEhC,IAAAC,kBAAS,EAAE,MAAM;IAChBF,eAAe,CAACG,OAAO,GACtBC,QAAQ,CAACC,aAAa,CAAEC,wCAA8B,CAAC,IACvDF,QAAQ,CAACC,aAAa,CAAEE,gCAAsB,CAAC;EACjD,CAAC,EAAE,EAAG,CAAC;EAEP,IAAAL,kBAAS,EAAE,MAAM;IAChB,IAAK,CAAER,YAAY,IAAI,CAAEM,eAAe,CAACG,OAAO,EAAG;MAClD;IACD;IACAH,eAAe,CAACG,OAAO,CAACK,YAAY,CAAE,MAAM,EAAEd,YAAa,CAAC;EAC7D,CAAC,EAAE,CAAEA,YAAY,CAAG,CAAC;AACtB,CAAC;AAACe,OAAA,CAAAhB,yBAAA,GAAAA,yBAAA","ignoreList":[]}
1
+ {"version":3,"names":["_data","require","_element","_editor","_coreData","_constants","useUpdatePostLinkListener","isViewable","newPermalink","useSelect","select","getPostType","coreStore","getCurrentPost","getEditedPostAttribute","editorStore","postType","viewable","link","nodeToUpdateRef","useRef","useEffect","current","document","querySelector","VIEW_AS_PREVIEW_LINK_SELECTOR","VIEW_AS_LINK_SELECTOR","style","display","setAttribute","exports"],"sources":["@wordpress/edit-post/src/components/editor-initialization/listener-hooks.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { useEffect, useRef } from '@wordpress/element';\nimport { store as editorStore } from '@wordpress/editor';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport {\n\tVIEW_AS_LINK_SELECTOR,\n\tVIEW_AS_PREVIEW_LINK_SELECTOR,\n} from '../../store/constants';\n\n/**\n * This listener hook monitors any change in permalink and updates the view\n * post link in the admin bar.\n */\nexport const useUpdatePostLinkListener = () => {\n\tconst { isViewable, newPermalink } = useSelect( ( select ) => {\n\t\tconst { getPostType } = select( coreStore );\n\t\tconst { getCurrentPost, getEditedPostAttribute } =\n\t\t\tselect( editorStore );\n\t\tconst postType = getPostType( getEditedPostAttribute( 'type' ) );\n\t\treturn {\n\t\t\tisViewable: postType?.viewable,\n\t\t\tnewPermalink: getCurrentPost().link,\n\t\t};\n\t}, [] );\n\n\tconst nodeToUpdateRef = useRef();\n\n\tuseEffect( () => {\n\t\tnodeToUpdateRef.current =\n\t\t\tdocument.querySelector( VIEW_AS_PREVIEW_LINK_SELECTOR ) ||\n\t\t\tdocument.querySelector( VIEW_AS_LINK_SELECTOR );\n\t}, [] );\n\n\tuseEffect( () => {\n\t\tif ( ! newPermalink || ! nodeToUpdateRef.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( ! isViewable ) {\n\t\t\tnodeToUpdateRef.current.style.display = 'none';\n\t\t\treturn;\n\t\t}\n\n\t\tnodeToUpdateRef.current.style.display = '';\n\t\tnodeToUpdateRef.current.setAttribute( 'href', newPermalink );\n\t}, [ newPermalink, isViewable ] );\n};\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AAKA,IAAAI,UAAA,GAAAJ,OAAA;AAXA;AACA;AACA;;AAMA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACO,MAAMK,yBAAyB,GAAGA,CAAA,KAAM;EAC9C,MAAM;IAAEC,UAAU;IAAEC;EAAa,CAAC,GAAG,IAAAC,eAAS,EAAIC,MAAM,IAAM;IAC7D,MAAM;MAAEC;IAAY,CAAC,GAAGD,MAAM,CAAEE,eAAU,CAAC;IAC3C,MAAM;MAAEC,cAAc;MAAEC;IAAuB,CAAC,GAC/CJ,MAAM,CAAEK,aAAY,CAAC;IACtB,MAAMC,QAAQ,GAAGL,WAAW,CAAEG,sBAAsB,CAAE,MAAO,CAAE,CAAC;IAChE,OAAO;MACNP,UAAU,EAAES,QAAQ,EAAEC,QAAQ;MAC9BT,YAAY,EAAEK,cAAc,CAAC,CAAC,CAACK;IAChC,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;EAEP,MAAMC,eAAe,GAAG,IAAAC,eAAM,EAAC,CAAC;EAEhC,IAAAC,kBAAS,EAAE,MAAM;IAChBF,eAAe,CAACG,OAAO,GACtBC,QAAQ,CAACC,aAAa,CAAEC,wCAA8B,CAAC,IACvDF,QAAQ,CAACC,aAAa,CAAEE,gCAAsB,CAAC;EACjD,CAAC,EAAE,EAAG,CAAC;EAEP,IAAAL,kBAAS,EAAE,MAAM;IAChB,IAAK,CAAEb,YAAY,IAAI,CAAEW,eAAe,CAACG,OAAO,EAAG;MAClD;IACD;IAEA,IAAK,CAAEf,UAAU,EAAG;MACnBY,eAAe,CAACG,OAAO,CAACK,KAAK,CAACC,OAAO,GAAG,MAAM;MAC9C;IACD;IAEAT,eAAe,CAACG,OAAO,CAACK,KAAK,CAACC,OAAO,GAAG,EAAE;IAC1CT,eAAe,CAACG,OAAO,CAACO,YAAY,CAAE,MAAM,EAAErB,YAAa,CAAC;EAC7D,CAAC,EAAE,CAAEA,YAAY,EAAED,UAAU,CAAG,CAAC;AAClC,CAAC;AAACuB,OAAA,CAAAxB,yBAAA,GAAAA,yBAAA","ignoreList":[]}
@@ -4,6 +4,7 @@
4
4
  import { useSelect } from '@wordpress/data';
5
5
  import { useEffect, useRef } from '@wordpress/element';
6
6
  import { store as editorStore } from '@wordpress/editor';
7
+ import { store as coreStore } from '@wordpress/core-data';
7
8
 
8
9
  /**
9
10
  * Internal dependencies
@@ -16,10 +17,22 @@ import { VIEW_AS_LINK_SELECTOR, VIEW_AS_PREVIEW_LINK_SELECTOR } from '../../stor
16
17
  */
17
18
  export const useUpdatePostLinkListener = () => {
18
19
  const {
20
+ isViewable,
19
21
  newPermalink
20
- } = useSelect(select => ({
21
- newPermalink: select(editorStore).getCurrentPost().link
22
- }), []);
22
+ } = useSelect(select => {
23
+ const {
24
+ getPostType
25
+ } = select(coreStore);
26
+ const {
27
+ getCurrentPost,
28
+ getEditedPostAttribute
29
+ } = select(editorStore);
30
+ const postType = getPostType(getEditedPostAttribute('type'));
31
+ return {
32
+ isViewable: postType?.viewable,
33
+ newPermalink: getCurrentPost().link
34
+ };
35
+ }, []);
23
36
  const nodeToUpdateRef = useRef();
24
37
  useEffect(() => {
25
38
  nodeToUpdateRef.current = document.querySelector(VIEW_AS_PREVIEW_LINK_SELECTOR) || document.querySelector(VIEW_AS_LINK_SELECTOR);
@@ -28,7 +41,12 @@ export const useUpdatePostLinkListener = () => {
28
41
  if (!newPermalink || !nodeToUpdateRef.current) {
29
42
  return;
30
43
  }
44
+ if (!isViewable) {
45
+ nodeToUpdateRef.current.style.display = 'none';
46
+ return;
47
+ }
48
+ nodeToUpdateRef.current.style.display = '';
31
49
  nodeToUpdateRef.current.setAttribute('href', newPermalink);
32
- }, [newPermalink]);
50
+ }, [newPermalink, isViewable]);
33
51
  };
34
52
  //# sourceMappingURL=listener-hooks.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["useSelect","useEffect","useRef","store","editorStore","VIEW_AS_LINK_SELECTOR","VIEW_AS_PREVIEW_LINK_SELECTOR","useUpdatePostLinkListener","newPermalink","select","getCurrentPost","link","nodeToUpdateRef","current","document","querySelector","setAttribute"],"sources":["@wordpress/edit-post/src/components/editor-initialization/listener-hooks.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { useEffect, useRef } from '@wordpress/element';\nimport { store as editorStore } from '@wordpress/editor';\n\n/**\n * Internal dependencies\n */\nimport {\n\tVIEW_AS_LINK_SELECTOR,\n\tVIEW_AS_PREVIEW_LINK_SELECTOR,\n} from '../../store/constants';\n\n/**\n * This listener hook monitors any change in permalink and updates the view\n * post link in the admin bar.\n */\nexport const useUpdatePostLinkListener = () => {\n\tconst { newPermalink } = useSelect(\n\t\t( select ) => ( {\n\t\t\tnewPermalink: select( editorStore ).getCurrentPost().link,\n\t\t} ),\n\t\t[]\n\t);\n\tconst nodeToUpdateRef = useRef();\n\n\tuseEffect( () => {\n\t\tnodeToUpdateRef.current =\n\t\t\tdocument.querySelector( VIEW_AS_PREVIEW_LINK_SELECTOR ) ||\n\t\t\tdocument.querySelector( VIEW_AS_LINK_SELECTOR );\n\t}, [] );\n\n\tuseEffect( () => {\n\t\tif ( ! newPermalink || ! nodeToUpdateRef.current ) {\n\t\t\treturn;\n\t\t}\n\t\tnodeToUpdateRef.current.setAttribute( 'href', newPermalink );\n\t}, [ newPermalink ] );\n};\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,SAAS,EAAEC,MAAM,QAAQ,oBAAoB;AACtD,SAASC,KAAK,IAAIC,WAAW,QAAQ,mBAAmB;;AAExD;AACA;AACA;AACA,SACCC,qBAAqB,EACrBC,6BAA6B,QACvB,uBAAuB;;AAE9B;AACA;AACA;AACA;AACA,OAAO,MAAMC,yBAAyB,GAAGA,CAAA,KAAM;EAC9C,MAAM;IAAEC;EAAa,CAAC,GAAGR,SAAS,CAC/BS,MAAM,KAAQ;IACfD,YAAY,EAAEC,MAAM,CAAEL,WAAY,CAAC,CAACM,cAAc,CAAC,CAAC,CAACC;EACtD,CAAC,CAAE,EACH,EACD,CAAC;EACD,MAAMC,eAAe,GAAGV,MAAM,CAAC,CAAC;EAEhCD,SAAS,CAAE,MAAM;IAChBW,eAAe,CAACC,OAAO,GACtBC,QAAQ,CAACC,aAAa,CAAET,6BAA8B,CAAC,IACvDQ,QAAQ,CAACC,aAAa,CAAEV,qBAAsB,CAAC;EACjD,CAAC,EAAE,EAAG,CAAC;EAEPJ,SAAS,CAAE,MAAM;IAChB,IAAK,CAAEO,YAAY,IAAI,CAAEI,eAAe,CAACC,OAAO,EAAG;MAClD;IACD;IACAD,eAAe,CAACC,OAAO,CAACG,YAAY,CAAE,MAAM,EAAER,YAAa,CAAC;EAC7D,CAAC,EAAE,CAAEA,YAAY,CAAG,CAAC;AACtB,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["useSelect","useEffect","useRef","store","editorStore","coreStore","VIEW_AS_LINK_SELECTOR","VIEW_AS_PREVIEW_LINK_SELECTOR","useUpdatePostLinkListener","isViewable","newPermalink","select","getPostType","getCurrentPost","getEditedPostAttribute","postType","viewable","link","nodeToUpdateRef","current","document","querySelector","style","display","setAttribute"],"sources":["@wordpress/edit-post/src/components/editor-initialization/listener-hooks.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { useEffect, useRef } from '@wordpress/element';\nimport { store as editorStore } from '@wordpress/editor';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport {\n\tVIEW_AS_LINK_SELECTOR,\n\tVIEW_AS_PREVIEW_LINK_SELECTOR,\n} from '../../store/constants';\n\n/**\n * This listener hook monitors any change in permalink and updates the view\n * post link in the admin bar.\n */\nexport const useUpdatePostLinkListener = () => {\n\tconst { isViewable, newPermalink } = useSelect( ( select ) => {\n\t\tconst { getPostType } = select( coreStore );\n\t\tconst { getCurrentPost, getEditedPostAttribute } =\n\t\t\tselect( editorStore );\n\t\tconst postType = getPostType( getEditedPostAttribute( 'type' ) );\n\t\treturn {\n\t\t\tisViewable: postType?.viewable,\n\t\t\tnewPermalink: getCurrentPost().link,\n\t\t};\n\t}, [] );\n\n\tconst nodeToUpdateRef = useRef();\n\n\tuseEffect( () => {\n\t\tnodeToUpdateRef.current =\n\t\t\tdocument.querySelector( VIEW_AS_PREVIEW_LINK_SELECTOR ) ||\n\t\t\tdocument.querySelector( VIEW_AS_LINK_SELECTOR );\n\t}, [] );\n\n\tuseEffect( () => {\n\t\tif ( ! newPermalink || ! nodeToUpdateRef.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( ! isViewable ) {\n\t\t\tnodeToUpdateRef.current.style.display = 'none';\n\t\t\treturn;\n\t\t}\n\n\t\tnodeToUpdateRef.current.style.display = '';\n\t\tnodeToUpdateRef.current.setAttribute( 'href', newPermalink );\n\t}, [ newPermalink, isViewable ] );\n};\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,SAAS,EAAEC,MAAM,QAAQ,oBAAoB;AACtD,SAASC,KAAK,IAAIC,WAAW,QAAQ,mBAAmB;AACxD,SAASD,KAAK,IAAIE,SAAS,QAAQ,sBAAsB;;AAEzD;AACA;AACA;AACA,SACCC,qBAAqB,EACrBC,6BAA6B,QACvB,uBAAuB;;AAE9B;AACA;AACA;AACA;AACA,OAAO,MAAMC,yBAAyB,GAAGA,CAAA,KAAM;EAC9C,MAAM;IAAEC,UAAU;IAAEC;EAAa,CAAC,GAAGV,SAAS,CAAIW,MAAM,IAAM;IAC7D,MAAM;MAAEC;IAAY,CAAC,GAAGD,MAAM,CAAEN,SAAU,CAAC;IAC3C,MAAM;MAAEQ,cAAc;MAAEC;IAAuB,CAAC,GAC/CH,MAAM,CAAEP,WAAY,CAAC;IACtB,MAAMW,QAAQ,GAAGH,WAAW,CAAEE,sBAAsB,CAAE,MAAO,CAAE,CAAC;IAChE,OAAO;MACNL,UAAU,EAAEM,QAAQ,EAAEC,QAAQ;MAC9BN,YAAY,EAAEG,cAAc,CAAC,CAAC,CAACI;IAChC,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;EAEP,MAAMC,eAAe,GAAGhB,MAAM,CAAC,CAAC;EAEhCD,SAAS,CAAE,MAAM;IAChBiB,eAAe,CAACC,OAAO,GACtBC,QAAQ,CAACC,aAAa,CAAEd,6BAA8B,CAAC,IACvDa,QAAQ,CAACC,aAAa,CAAEf,qBAAsB,CAAC;EACjD,CAAC,EAAE,EAAG,CAAC;EAEPL,SAAS,CAAE,MAAM;IAChB,IAAK,CAAES,YAAY,IAAI,CAAEQ,eAAe,CAACC,OAAO,EAAG;MAClD;IACD;IAEA,IAAK,CAAEV,UAAU,EAAG;MACnBS,eAAe,CAACC,OAAO,CAACG,KAAK,CAACC,OAAO,GAAG,MAAM;MAC9C;IACD;IAEAL,eAAe,CAACC,OAAO,CAACG,KAAK,CAACC,OAAO,GAAG,EAAE;IAC1CL,eAAe,CAACC,OAAO,CAACK,YAAY,CAAE,MAAM,EAAEd,YAAa,CAAC;EAC7D,CAAC,EAAE,CAAEA,YAAY,EAAED,UAAU,CAAG,CAAC;AAClC,CAAC","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/edit-post",
3
- "version": "8.30.0",
3
+ "version": "8.30.1-next.836ecdcae.0",
4
4
  "description": "Edit Post module for WordPress.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -29,34 +29,34 @@
29
29
  "wpScript": true,
30
30
  "dependencies": {
31
31
  "@babel/runtime": "7.25.7",
32
- "@wordpress/a11y": "^4.30.0",
33
- "@wordpress/api-fetch": "^7.30.0",
34
- "@wordpress/block-editor": "^15.3.0",
35
- "@wordpress/block-library": "^9.30.0",
36
- "@wordpress/blocks": "^15.3.0",
37
- "@wordpress/commands": "^1.30.0",
38
- "@wordpress/components": "^30.3.0",
39
- "@wordpress/compose": "^7.30.0",
40
- "@wordpress/core-data": "^7.30.0",
41
- "@wordpress/data": "^10.30.0",
42
- "@wordpress/deprecated": "^4.30.0",
43
- "@wordpress/dom": "^4.30.0",
44
- "@wordpress/editor": "^14.30.0",
45
- "@wordpress/element": "^6.30.0",
46
- "@wordpress/hooks": "^4.30.0",
47
- "@wordpress/html-entities": "^4.30.0",
48
- "@wordpress/i18n": "^6.3.0",
49
- "@wordpress/icons": "^10.30.0",
50
- "@wordpress/keyboard-shortcuts": "^5.30.0",
51
- "@wordpress/keycodes": "^4.30.0",
52
- "@wordpress/notices": "^5.30.0",
53
- "@wordpress/plugins": "^7.30.0",
54
- "@wordpress/preferences": "^4.30.0",
55
- "@wordpress/private-apis": "^1.30.0",
56
- "@wordpress/url": "^4.30.0",
57
- "@wordpress/viewport": "^6.30.0",
58
- "@wordpress/warning": "^3.30.0",
59
- "@wordpress/widgets": "^4.30.0",
32
+ "@wordpress/a11y": "^4.30.1-next.836ecdcae.0",
33
+ "@wordpress/api-fetch": "^7.30.1-next.836ecdcae.0",
34
+ "@wordpress/block-editor": "^15.3.1-next.836ecdcae.0",
35
+ "@wordpress/block-library": "^9.30.1-next.836ecdcae.0",
36
+ "@wordpress/blocks": "^15.3.1-next.836ecdcae.0",
37
+ "@wordpress/commands": "^1.30.1-next.836ecdcae.0",
38
+ "@wordpress/components": "^30.3.2-next.836ecdcae.0",
39
+ "@wordpress/compose": "^7.30.1-next.836ecdcae.0",
40
+ "@wordpress/core-data": "^7.30.1-next.836ecdcae.0",
41
+ "@wordpress/data": "^10.30.1-next.836ecdcae.0",
42
+ "@wordpress/deprecated": "^4.30.1-next.836ecdcae.0",
43
+ "@wordpress/dom": "^4.30.1-next.836ecdcae.0",
44
+ "@wordpress/editor": "^14.30.1-next.836ecdcae.0",
45
+ "@wordpress/element": "^6.30.1-next.836ecdcae.0",
46
+ "@wordpress/hooks": "^4.30.1-next.836ecdcae.0",
47
+ "@wordpress/html-entities": "^4.30.1-next.836ecdcae.0",
48
+ "@wordpress/i18n": "^6.3.1-next.836ecdcae.0",
49
+ "@wordpress/icons": "^10.30.1-next.836ecdcae.0",
50
+ "@wordpress/keyboard-shortcuts": "^5.30.1-next.836ecdcae.0",
51
+ "@wordpress/keycodes": "^4.30.1-next.836ecdcae.0",
52
+ "@wordpress/notices": "^5.30.1-next.836ecdcae.0",
53
+ "@wordpress/plugins": "^7.30.1-next.836ecdcae.0",
54
+ "@wordpress/preferences": "^4.30.1-next.836ecdcae.0",
55
+ "@wordpress/private-apis": "^1.30.1-next.836ecdcae.0",
56
+ "@wordpress/url": "^4.30.1-next.836ecdcae.0",
57
+ "@wordpress/viewport": "^6.30.1-next.836ecdcae.0",
58
+ "@wordpress/warning": "^3.30.1-next.836ecdcae.0",
59
+ "@wordpress/widgets": "^4.30.1-next.836ecdcae.0",
60
60
  "clsx": "^2.1.1",
61
61
  "memize": "^2.1.0"
62
62
  },
@@ -67,5 +67,5 @@
67
67
  "publishConfig": {
68
68
  "access": "public"
69
69
  },
70
- "gitHead": "c66cb089eed19d4f4956962fa7b4c81abe6dd513"
70
+ "gitHead": "3e60b4c1e78d7b27acbf1d7dd172bbd64358a0f2"
71
71
  }
@@ -4,6 +4,7 @@
4
4
  import { useSelect } from '@wordpress/data';
5
5
  import { useEffect, useRef } from '@wordpress/element';
6
6
  import { store as editorStore } from '@wordpress/editor';
7
+ import { store as coreStore } from '@wordpress/core-data';
7
8
 
8
9
  /**
9
10
  * Internal dependencies
@@ -18,12 +19,17 @@ import {
18
19
  * post link in the admin bar.
19
20
  */
20
21
  export const useUpdatePostLinkListener = () => {
21
- const { newPermalink } = useSelect(
22
- ( select ) => ( {
23
- newPermalink: select( editorStore ).getCurrentPost().link,
24
- } ),
25
- []
26
- );
22
+ const { isViewable, newPermalink } = useSelect( ( select ) => {
23
+ const { getPostType } = select( coreStore );
24
+ const { getCurrentPost, getEditedPostAttribute } =
25
+ select( editorStore );
26
+ const postType = getPostType( getEditedPostAttribute( 'type' ) );
27
+ return {
28
+ isViewable: postType?.viewable,
29
+ newPermalink: getCurrentPost().link,
30
+ };
31
+ }, [] );
32
+
27
33
  const nodeToUpdateRef = useRef();
28
34
 
29
35
  useEffect( () => {
@@ -36,6 +42,13 @@ export const useUpdatePostLinkListener = () => {
36
42
  if ( ! newPermalink || ! nodeToUpdateRef.current ) {
37
43
  return;
38
44
  }
45
+
46
+ if ( ! isViewable ) {
47
+ nodeToUpdateRef.current.style.display = 'none';
48
+ return;
49
+ }
50
+
51
+ nodeToUpdateRef.current.style.display = '';
39
52
  nodeToUpdateRef.current.setAttribute( 'href', newPermalink );
40
- }, [ newPermalink ] );
53
+ }, [ newPermalink, isViewable ] );
41
54
  };
@@ -33,6 +33,14 @@ describe( 'listener hook tests', () => {
33
33
  ...storeConfig,
34
34
  selectors: {
35
35
  getCurrentPost: jest.fn(),
36
+ getCurrentPostType: jest.fn(),
37
+ getEditedPostAttribute: jest.fn(),
38
+ },
39
+ },
40
+ core: {
41
+ ...storeConfig,
42
+ selectors: {
43
+ getPostType: jest.fn(),
36
44
  },
37
45
  },
38
46
  'core/viewport': {
@@ -69,6 +77,13 @@ describe( 'listener hook tests', () => {
69
77
  mockStores[ store ].selectors[ functionName ].mockReturnValue( value );
70
78
  };
71
79
 
80
+ const setupPostTypeScenario = ( postType, isViewable = true ) => {
81
+ setMockReturnValue( 'core/editor', 'getEditedPostAttribute', postType );
82
+ setMockReturnValue( 'core', 'getPostType', {
83
+ viewable: isViewable,
84
+ } );
85
+ };
86
+
72
87
  afterEach( () => {
73
88
  Object.values( mockStores ).forEach( ( storeMocks ) => {
74
89
  Object.values( storeMocks.selectors ).forEach( ( mock ) => {
@@ -95,28 +110,36 @@ describe( 'listener hook tests', () => {
95
110
  };
96
111
 
97
112
  const setAttribute = jest.fn();
113
+ const mockElement = {
114
+ setAttribute,
115
+ style: { display: '' },
116
+ };
98
117
  const mockSelector = jest.fn();
99
118
  beforeEach( () => {
119
+ // Reset the mock element style
120
+ mockElement.style.display = '';
100
121
  // eslint-disable-next-line testing-library/no-node-access
101
- document.querySelector = mockSelector.mockReturnValue( {
102
- setAttribute,
103
- } );
122
+ document.querySelector =
123
+ mockSelector.mockReturnValue( mockElement );
104
124
  } );
105
125
  afterEach( () => {
106
126
  setAttribute.mockClear();
107
127
  mockSelector.mockClear();
128
+ mockElement.style.display = '';
108
129
  } );
109
130
  it( 'updates nothing if there is no view link available', () => {
110
131
  mockSelector.mockImplementation( () => null );
111
132
  setMockReturnValue( 'core/editor', 'getCurrentPost', {
112
133
  link: 'foo',
113
134
  } );
135
+ setupPostTypeScenario( 'post', true );
114
136
  render( <TestedOutput /> );
115
137
 
116
138
  expect( setAttribute ).not.toHaveBeenCalled();
117
139
  } );
118
140
  it( 'updates nothing if there is no permalink', () => {
119
141
  setMockReturnValue( 'core/editor', 'getCurrentPost', { link: '' } );
142
+ setupPostTypeScenario( 'post', true );
120
143
  render( <TestedOutput /> );
121
144
 
122
145
  expect( setAttribute ).not.toHaveBeenCalled();
@@ -125,6 +148,7 @@ describe( 'listener hook tests', () => {
125
148
  setMockReturnValue( 'core/editor', 'getCurrentPost', {
126
149
  link: 'foo',
127
150
  } );
151
+ setupPostTypeScenario( 'post', true );
128
152
  const { rerender } = render( <TestedOutput /> );
129
153
 
130
154
  rerender( <TestedOutput /> );
@@ -139,6 +163,7 @@ describe( 'listener hook tests', () => {
139
163
  setMockReturnValue( 'core/editor', 'getCurrentPost', {
140
164
  link: 'foo',
141
165
  } );
166
+ setupPostTypeScenario( 'post', true );
142
167
  render( <TestedOutput /> );
143
168
  expect( setAttribute ).toHaveBeenCalledTimes( 1 );
144
169
  act( () => {
@@ -150,6 +175,7 @@ describe( 'listener hook tests', () => {
150
175
  setMockReturnValue( 'core/editor', 'getCurrentPost', {
151
176
  link: 'foo',
152
177
  } );
178
+ setupPostTypeScenario( 'post', true );
153
179
  render( <TestedOutput /> );
154
180
  expect( setAttribute ).toHaveBeenCalledTimes( 1 );
155
181
  expect( setAttribute ).toHaveBeenCalledWith( 'href', 'foo' );
@@ -163,5 +189,15 @@ describe( 'listener hook tests', () => {
163
189
  expect( setAttribute ).toHaveBeenCalledTimes( 2 );
164
190
  expect( setAttribute ).toHaveBeenCalledWith( 'href', 'bar' );
165
191
  } );
192
+ it( 'hides the "View Post" link when editing non-viewable post types', () => {
193
+ setMockReturnValue( 'core/editor', 'getCurrentPost', {
194
+ link: 'foo',
195
+ } );
196
+ setupPostTypeScenario( 'wp_block', false );
197
+ render( <TestedOutput /> );
198
+
199
+ expect( setAttribute ).not.toHaveBeenCalled();
200
+ expect( mockElement ).toHaveProperty( 'style.display', 'none' );
201
+ } );
166
202
  } );
167
203
  } );