@wordpress/editor 14.28.0 → 14.29.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/collab-sidebar/comments.js +1 -1
- package/build/components/collab-sidebar/comments.js.map +1 -1
- package/build/components/document-bar/index.js +1 -1
- package/build/components/document-bar/index.js.map +1 -1
- package/build/hooks/index.js +1 -0
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/navigation-link-view-button.js +76 -0
- package/build/hooks/navigation-link-view-button.js.map +1 -0
- package/build-module/components/collab-sidebar/comments.js +1 -1
- package/build-module/components/collab-sidebar/comments.js.map +1 -1
- package/build-module/components/document-bar/index.js +1 -1
- package/build-module/components/document-bar/index.js.map +1 -1
- package/build-module/hooks/index.js +1 -0
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/navigation-link-view-button.js +74 -0
- package/build-module/hooks/navigation-link-view-button.js.map +1 -0
- package/build-style/style-rtl.css +2 -1
- package/build-style/style.css +2 -1
- package/build-types/hooks/navigation-link-view-button.d.ts +2 -0
- package/build-types/hooks/navigation-link-view-button.d.ts.map +1 -0
- package/package.json +37 -37
- package/src/components/collab-sidebar/comments.js +1 -4
- package/src/components/document-bar/index.js +1 -1
- package/src/components/post-url/style.scss +2 -1
- package/src/hooks/index.js +1 -0
- package/src/hooks/navigation-link-view-button.js +100 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { addFilter } from '@wordpress/hooks';
|
|
5
|
+
import { createHigherOrderComponent } from '@wordpress/compose';
|
|
6
|
+
import { useCallback } from '@wordpress/element';
|
|
7
|
+
import { __ } from '@wordpress/i18n';
|
|
8
|
+
import { __unstableBlockToolbarLastItem as BlockToolbarLastItem, store as blockEditorStore, useBlockEditingMode } from '@wordpress/block-editor';
|
|
9
|
+
import { ToolbarButton, ToolbarGroup } from '@wordpress/components';
|
|
10
|
+
import { useSelect } from '@wordpress/data';
|
|
11
|
+
|
|
12
|
+
// Target blocks that should have the View button.
|
|
13
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
const SUPPORTED_BLOCKS = ['core/navigation-link', 'core/navigation-submenu'];
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Component that renders the View button for navigation blocks.
|
|
18
|
+
*
|
|
19
|
+
* @param {Object} props Component props.
|
|
20
|
+
* @param {Object} props.attributes Block attributes.
|
|
21
|
+
* @return {JSX.Element|null} The View button component or null if not applicable.
|
|
22
|
+
*/
|
|
23
|
+
function NavigationViewButton({
|
|
24
|
+
attributes
|
|
25
|
+
}) {
|
|
26
|
+
const {
|
|
27
|
+
kind,
|
|
28
|
+
id,
|
|
29
|
+
type
|
|
30
|
+
} = attributes;
|
|
31
|
+
const blockEditingMode = useBlockEditingMode();
|
|
32
|
+
const onNavigateToEntityRecord = useSelect(select => select(blockEditorStore).getSettings().onNavigateToEntityRecord, []);
|
|
33
|
+
const onViewPage = useCallback(() => {
|
|
34
|
+
if (kind === 'post-type' && type === 'page' && id && onNavigateToEntityRecord) {
|
|
35
|
+
onNavigateToEntityRecord({
|
|
36
|
+
postId: id,
|
|
37
|
+
postType: type
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}, [kind, id, type, onNavigateToEntityRecord]);
|
|
41
|
+
|
|
42
|
+
// Only show for page-type links, when navigation is available, and when in contentOnly mode.
|
|
43
|
+
if (kind !== 'post-type' || type !== 'page' || !id || !onNavigateToEntityRecord || blockEditingMode !== 'contentOnly') {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
return /*#__PURE__*/_jsx(BlockToolbarLastItem, {
|
|
47
|
+
children: /*#__PURE__*/_jsx(ToolbarGroup, {
|
|
48
|
+
children: /*#__PURE__*/_jsx(ToolbarButton, {
|
|
49
|
+
name: "view",
|
|
50
|
+
title: __('View'),
|
|
51
|
+
onClick: onViewPage,
|
|
52
|
+
children: __('View')
|
|
53
|
+
})
|
|
54
|
+
})
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Higher-order component that adds the View button to navigation blocks.
|
|
60
|
+
*/
|
|
61
|
+
const withNavigationViewButton = createHigherOrderComponent(BlockEdit => props => {
|
|
62
|
+
const isSupportedBlock = SUPPORTED_BLOCKS.includes(props.name);
|
|
63
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
64
|
+
children: [/*#__PURE__*/_jsx(BlockEdit, {
|
|
65
|
+
...props
|
|
66
|
+
}, "edit"), props.isSelected && isSupportedBlock && /*#__PURE__*/_jsx(NavigationViewButton, {
|
|
67
|
+
...props
|
|
68
|
+
})]
|
|
69
|
+
});
|
|
70
|
+
}, 'withNavigationViewButton');
|
|
71
|
+
|
|
72
|
+
// Register the filter.
|
|
73
|
+
addFilter('editor.BlockEdit', 'core/editor/with-navigation-view-button', withNavigationViewButton);
|
|
74
|
+
//# sourceMappingURL=navigation-link-view-button.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["addFilter","createHigherOrderComponent","useCallback","__","__unstableBlockToolbarLastItem","BlockToolbarLastItem","store","blockEditorStore","useBlockEditingMode","ToolbarButton","ToolbarGroup","useSelect","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","SUPPORTED_BLOCKS","NavigationViewButton","attributes","kind","id","type","blockEditingMode","onNavigateToEntityRecord","select","getSettings","onViewPage","postId","postType","children","name","title","onClick","withNavigationViewButton","BlockEdit","props","isSupportedBlock","includes","isSelected"],"sources":["@wordpress/editor/src/hooks/navigation-link-view-button.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { useCallback } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\t__unstableBlockToolbarLastItem as BlockToolbarLastItem,\n\tstore as blockEditorStore,\n\tuseBlockEditingMode,\n} from '@wordpress/block-editor';\nimport { ToolbarButton, ToolbarGroup } from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\n\n// Target blocks that should have the View button.\nconst SUPPORTED_BLOCKS = [ 'core/navigation-link', 'core/navigation-submenu' ];\n\n/**\n * Component that renders the View button for navigation blocks.\n *\n * @param {Object} props Component props.\n * @param {Object} props.attributes Block attributes.\n * @return {JSX.Element|null} The View button component or null if not applicable.\n */\nfunction NavigationViewButton( { attributes } ) {\n\tconst { kind, id, type } = attributes;\n\tconst blockEditingMode = useBlockEditingMode();\n\n\tconst onNavigateToEntityRecord = useSelect(\n\t\t( select ) =>\n\t\t\tselect( blockEditorStore ).getSettings().onNavigateToEntityRecord,\n\t\t[]\n\t);\n\n\tconst onViewPage = useCallback( () => {\n\t\tif (\n\t\t\tkind === 'post-type' &&\n\t\t\ttype === 'page' &&\n\t\t\tid &&\n\t\t\tonNavigateToEntityRecord\n\t\t) {\n\t\t\tonNavigateToEntityRecord( {\n\t\t\t\tpostId: id,\n\t\t\t\tpostType: type,\n\t\t\t} );\n\t\t}\n\t}, [ kind, id, type, onNavigateToEntityRecord ] );\n\n\t// Only show for page-type links, when navigation is available, and when in contentOnly mode.\n\tif (\n\t\tkind !== 'post-type' ||\n\t\ttype !== 'page' ||\n\t\t! id ||\n\t\t! onNavigateToEntityRecord ||\n\t\tblockEditingMode !== 'contentOnly'\n\t) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<BlockToolbarLastItem>\n\t\t\t<ToolbarGroup>\n\t\t\t\t<ToolbarButton\n\t\t\t\t\tname=\"view\"\n\t\t\t\t\ttitle={ __( 'View' ) }\n\t\t\t\t\tonClick={ onViewPage }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'View' ) }\n\t\t\t\t</ToolbarButton>\n\t\t\t</ToolbarGroup>\n\t\t</BlockToolbarLastItem>\n\t);\n}\n\n/**\n * Higher-order component that adds the View button to navigation blocks.\n */\nconst withNavigationViewButton = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tconst isSupportedBlock = SUPPORTED_BLOCKS.includes( props.name );\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<BlockEdit key=\"edit\" { ...props } />\n\t\t\t\t{ props.isSelected && isSupportedBlock && (\n\t\t\t\t\t<NavigationViewButton { ...props } />\n\t\t\t\t) }\n\t\t\t</>\n\t\t);\n\t},\n\t'withNavigationViewButton'\n);\n\n// Register the filter.\naddFilter(\n\t'editor.BlockEdit',\n\t'core/editor/with-navigation-view-button',\n\twithNavigationViewButton\n);\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,QAAQ,kBAAkB;AAC5C,SAASC,0BAA0B,QAAQ,oBAAoB;AAC/D,SAASC,WAAW,QAAQ,oBAAoB;AAChD,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SACCC,8BAA8B,IAAIC,oBAAoB,EACtDC,KAAK,IAAIC,gBAAgB,EACzBC,mBAAmB,QACb,yBAAyB;AAChC,SAASC,aAAa,EAAEC,YAAY,QAAQ,uBAAuB;AACnE,SAASC,SAAS,QAAQ,iBAAiB;;AAE3C;AAAA,SAAAC,GAAA,IAAAC,IAAA,EAAAC,QAAA,IAAAC,SAAA,EAAAC,IAAA,IAAAC,KAAA;AACA,MAAMC,gBAAgB,GAAG,CAAE,sBAAsB,EAAE,yBAAyB,CAAE;;AAE9E;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,oBAAoBA,CAAE;EAAEC;AAAW,CAAC,EAAG;EAC/C,MAAM;IAAEC,IAAI;IAAEC,EAAE;IAAEC;EAAK,CAAC,GAAGH,UAAU;EACrC,MAAMI,gBAAgB,GAAGhB,mBAAmB,CAAC,CAAC;EAE9C,MAAMiB,wBAAwB,GAAGd,SAAS,CACvCe,MAAM,IACPA,MAAM,CAAEnB,gBAAiB,CAAC,CAACoB,WAAW,CAAC,CAAC,CAACF,wBAAwB,EAClE,EACD,CAAC;EAED,MAAMG,UAAU,GAAG1B,WAAW,CAAE,MAAM;IACrC,IACCmB,IAAI,KAAK,WAAW,IACpBE,IAAI,KAAK,MAAM,IACfD,EAAE,IACFG,wBAAwB,EACvB;MACDA,wBAAwB,CAAE;QACzBI,MAAM,EAAEP,EAAE;QACVQ,QAAQ,EAAEP;MACX,CAAE,CAAC;IACJ;EACD,CAAC,EAAE,CAAEF,IAAI,EAAEC,EAAE,EAAEC,IAAI,EAAEE,wBAAwB,CAAG,CAAC;;EAEjD;EACA,IACCJ,IAAI,KAAK,WAAW,IACpBE,IAAI,KAAK,MAAM,IACf,CAAED,EAAE,IACJ,CAAEG,wBAAwB,IAC1BD,gBAAgB,KAAK,aAAa,EACjC;IACD,OAAO,IAAI;EACZ;EAEA,oBACCX,IAAA,CAACR,oBAAoB;IAAA0B,QAAA,eACpBlB,IAAA,CAACH,YAAY;MAAAqB,QAAA,eACZlB,IAAA,CAACJ,aAAa;QACbuB,IAAI,EAAC,MAAM;QACXC,KAAK,EAAG9B,EAAE,CAAE,MAAO,CAAG;QACtB+B,OAAO,EAAGN,UAAY;QAAAG,QAAA,EAEpB5B,EAAE,CAAE,MAAO;MAAC,CACA;IAAC,CACH;EAAC,CACM,CAAC;AAEzB;;AAEA;AACA;AACA;AACA,MAAMgC,wBAAwB,GAAGlC,0BAA0B,CACxDmC,SAAS,IAAQC,KAAK,IAAM;EAC7B,MAAMC,gBAAgB,GAAGpB,gBAAgB,CAACqB,QAAQ,CAAEF,KAAK,CAACL,IAAK,CAAC;EAEhE,oBACCf,KAAA,CAAAF,SAAA;IAAAgB,QAAA,gBACClB,IAAA,CAACuB,SAAS;MAAA,GAAiBC;IAAK,GAAjB,MAAqB,CAAC,EACnCA,KAAK,CAACG,UAAU,IAAIF,gBAAgB,iBACrCzB,IAAA,CAACM,oBAAoB;MAAA,GAAMkB;IAAK,CAAI,CACpC;EAAA,CACA,CAAC;AAEL,CAAC,EACD,0BACD,CAAC;;AAED;AACArC,SAAS,CACR,kBAAkB,EAClB,yCAAyC,EACzCmC,wBACD,CAAC","ignoreList":[]}
|
|
@@ -2316,7 +2316,8 @@ textarea.editor-post-text-editor:-ms-input-placeholder {
|
|
|
2316
2316
|
padding-inline-start: 0 !important;
|
|
2317
2317
|
}
|
|
2318
2318
|
|
|
2319
|
-
.editor-post-url__panel-toggle
|
|
2319
|
+
.editor-post-url__panel-toggle,
|
|
2320
|
+
.editor-post-parent__panel-toggle {
|
|
2320
2321
|
word-break: break-word;
|
|
2321
2322
|
}
|
|
2322
2323
|
|
package/build-style/style.css
CHANGED
|
@@ -2320,7 +2320,8 @@ textarea.editor-post-text-editor:-ms-input-placeholder {
|
|
|
2320
2320
|
padding-inline-start: 0 !important;
|
|
2321
2321
|
}
|
|
2322
2322
|
|
|
2323
|
-
.editor-post-url__panel-toggle
|
|
2323
|
+
.editor-post-url__panel-toggle,
|
|
2324
|
+
.editor-post-parent__panel-toggle {
|
|
2324
2325
|
word-break: break-word;
|
|
2325
2326
|
}
|
|
2326
2327
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigation-link-view-button.d.ts","sourceRoot":"","sources":["../../src/hooks/navigation-link-view-button.js"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/editor",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.29.0",
|
|
4
4
|
"description": "Enhanced block editor for WordPress posts.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -34,41 +34,41 @@
|
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@babel/runtime": "7.25.7",
|
|
37
|
-
"@wordpress/a11y": "^4.
|
|
38
|
-
"@wordpress/api-fetch": "^7.
|
|
39
|
-
"@wordpress/blob": "^4.
|
|
40
|
-
"@wordpress/block-editor": "^15.
|
|
41
|
-
"@wordpress/blocks": "^15.
|
|
42
|
-
"@wordpress/commands": "^1.
|
|
43
|
-
"@wordpress/components": "^30.
|
|
44
|
-
"@wordpress/compose": "^7.
|
|
45
|
-
"@wordpress/core-data": "^7.
|
|
46
|
-
"@wordpress/data": "^10.
|
|
47
|
-
"@wordpress/dataviews": "^
|
|
48
|
-
"@wordpress/date": "^5.
|
|
49
|
-
"@wordpress/deprecated": "^4.
|
|
50
|
-
"@wordpress/dom": "^4.
|
|
51
|
-
"@wordpress/element": "^6.
|
|
52
|
-
"@wordpress/fields": "^0.
|
|
53
|
-
"@wordpress/hooks": "^4.
|
|
54
|
-
"@wordpress/html-entities": "^4.
|
|
55
|
-
"@wordpress/i18n": "^6.
|
|
56
|
-
"@wordpress/icons": "^10.
|
|
57
|
-
"@wordpress/interface": "^9.
|
|
58
|
-
"@wordpress/keyboard-shortcuts": "^5.
|
|
59
|
-
"@wordpress/keycodes": "^4.
|
|
60
|
-
"@wordpress/media-utils": "^5.
|
|
61
|
-
"@wordpress/notices": "^5.
|
|
62
|
-
"@wordpress/patterns": "^2.
|
|
63
|
-
"@wordpress/plugins": "^7.
|
|
64
|
-
"@wordpress/preferences": "^4.
|
|
65
|
-
"@wordpress/private-apis": "^1.
|
|
66
|
-
"@wordpress/reusable-blocks": "^5.
|
|
67
|
-
"@wordpress/rich-text": "^7.
|
|
68
|
-
"@wordpress/server-side-render": "^6.
|
|
69
|
-
"@wordpress/url": "^4.
|
|
70
|
-
"@wordpress/warning": "^3.
|
|
71
|
-
"@wordpress/wordcount": "^4.
|
|
37
|
+
"@wordpress/a11y": "^4.29.0",
|
|
38
|
+
"@wordpress/api-fetch": "^7.29.0",
|
|
39
|
+
"@wordpress/blob": "^4.29.0",
|
|
40
|
+
"@wordpress/block-editor": "^15.2.0",
|
|
41
|
+
"@wordpress/blocks": "^15.2.0",
|
|
42
|
+
"@wordpress/commands": "^1.29.0",
|
|
43
|
+
"@wordpress/components": "^30.2.0",
|
|
44
|
+
"@wordpress/compose": "^7.29.0",
|
|
45
|
+
"@wordpress/core-data": "^7.29.0",
|
|
46
|
+
"@wordpress/data": "^10.29.0",
|
|
47
|
+
"@wordpress/dataviews": "^7.0.0",
|
|
48
|
+
"@wordpress/date": "^5.29.0",
|
|
49
|
+
"@wordpress/deprecated": "^4.29.0",
|
|
50
|
+
"@wordpress/dom": "^4.29.0",
|
|
51
|
+
"@wordpress/element": "^6.29.0",
|
|
52
|
+
"@wordpress/fields": "^0.21.0",
|
|
53
|
+
"@wordpress/hooks": "^4.29.0",
|
|
54
|
+
"@wordpress/html-entities": "^4.29.0",
|
|
55
|
+
"@wordpress/i18n": "^6.2.0",
|
|
56
|
+
"@wordpress/icons": "^10.29.0",
|
|
57
|
+
"@wordpress/interface": "^9.14.0",
|
|
58
|
+
"@wordpress/keyboard-shortcuts": "^5.29.0",
|
|
59
|
+
"@wordpress/keycodes": "^4.29.0",
|
|
60
|
+
"@wordpress/media-utils": "^5.29.0",
|
|
61
|
+
"@wordpress/notices": "^5.29.0",
|
|
62
|
+
"@wordpress/patterns": "^2.29.0",
|
|
63
|
+
"@wordpress/plugins": "^7.29.0",
|
|
64
|
+
"@wordpress/preferences": "^4.29.0",
|
|
65
|
+
"@wordpress/private-apis": "^1.29.0",
|
|
66
|
+
"@wordpress/reusable-blocks": "^5.29.0",
|
|
67
|
+
"@wordpress/rich-text": "^7.29.0",
|
|
68
|
+
"@wordpress/server-side-render": "^6.5.0",
|
|
69
|
+
"@wordpress/url": "^4.29.0",
|
|
70
|
+
"@wordpress/warning": "^3.29.0",
|
|
71
|
+
"@wordpress/wordcount": "^4.29.0",
|
|
72
72
|
"change-case": "^4.1.2",
|
|
73
73
|
"client-zip": "^2.4.5",
|
|
74
74
|
"clsx": "^2.1.1",
|
|
@@ -88,5 +88,5 @@
|
|
|
88
88
|
"publishConfig": {
|
|
89
89
|
"access": "public"
|
|
90
90
|
},
|
|
91
|
-
"gitHead": "
|
|
91
|
+
"gitHead": "445ede01e8abc8e49a1101b21a3651adbe852120"
|
|
92
92
|
}
|
|
@@ -145,10 +145,7 @@ function Thread( {
|
|
|
145
145
|
<VStack className="editor-collab-sidebar-panel__show-more-reply">
|
|
146
146
|
{ sprintf(
|
|
147
147
|
// translators: %s: number of replies.
|
|
148
|
-
_x(
|
|
149
|
-
'%s more replies..',
|
|
150
|
-
'Show replies button'
|
|
151
|
-
),
|
|
148
|
+
_x( '%s more replies', 'Show replies button' ),
|
|
152
149
|
thread?.reply?.length
|
|
153
150
|
) }
|
|
154
151
|
</VStack>
|
|
@@ -161,7 +161,7 @@ export default function DocumentBar( props ) {
|
|
|
161
161
|
</MotionButton>
|
|
162
162
|
) }
|
|
163
163
|
</AnimatePresence>
|
|
164
|
-
{ ! isTemplate && isTemplatePreview && (
|
|
164
|
+
{ ! isTemplate && isTemplatePreview && ! hasBackButton && (
|
|
165
165
|
<BlockIcon
|
|
166
166
|
icon={ layout }
|
|
167
167
|
className="editor-document-bar__icon-layout"
|
package/src/hooks/index.js
CHANGED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { addFilter } from '@wordpress/hooks';
|
|
5
|
+
import { createHigherOrderComponent } from '@wordpress/compose';
|
|
6
|
+
import { useCallback } from '@wordpress/element';
|
|
7
|
+
import { __ } from '@wordpress/i18n';
|
|
8
|
+
import {
|
|
9
|
+
__unstableBlockToolbarLastItem as BlockToolbarLastItem,
|
|
10
|
+
store as blockEditorStore,
|
|
11
|
+
useBlockEditingMode,
|
|
12
|
+
} from '@wordpress/block-editor';
|
|
13
|
+
import { ToolbarButton, ToolbarGroup } from '@wordpress/components';
|
|
14
|
+
import { useSelect } from '@wordpress/data';
|
|
15
|
+
|
|
16
|
+
// Target blocks that should have the View button.
|
|
17
|
+
const SUPPORTED_BLOCKS = [ 'core/navigation-link', 'core/navigation-submenu' ];
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Component that renders the View button for navigation blocks.
|
|
21
|
+
*
|
|
22
|
+
* @param {Object} props Component props.
|
|
23
|
+
* @param {Object} props.attributes Block attributes.
|
|
24
|
+
* @return {JSX.Element|null} The View button component or null if not applicable.
|
|
25
|
+
*/
|
|
26
|
+
function NavigationViewButton( { attributes } ) {
|
|
27
|
+
const { kind, id, type } = attributes;
|
|
28
|
+
const blockEditingMode = useBlockEditingMode();
|
|
29
|
+
|
|
30
|
+
const onNavigateToEntityRecord = useSelect(
|
|
31
|
+
( select ) =>
|
|
32
|
+
select( blockEditorStore ).getSettings().onNavigateToEntityRecord,
|
|
33
|
+
[]
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const onViewPage = useCallback( () => {
|
|
37
|
+
if (
|
|
38
|
+
kind === 'post-type' &&
|
|
39
|
+
type === 'page' &&
|
|
40
|
+
id &&
|
|
41
|
+
onNavigateToEntityRecord
|
|
42
|
+
) {
|
|
43
|
+
onNavigateToEntityRecord( {
|
|
44
|
+
postId: id,
|
|
45
|
+
postType: type,
|
|
46
|
+
} );
|
|
47
|
+
}
|
|
48
|
+
}, [ kind, id, type, onNavigateToEntityRecord ] );
|
|
49
|
+
|
|
50
|
+
// Only show for page-type links, when navigation is available, and when in contentOnly mode.
|
|
51
|
+
if (
|
|
52
|
+
kind !== 'post-type' ||
|
|
53
|
+
type !== 'page' ||
|
|
54
|
+
! id ||
|
|
55
|
+
! onNavigateToEntityRecord ||
|
|
56
|
+
blockEditingMode !== 'contentOnly'
|
|
57
|
+
) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<BlockToolbarLastItem>
|
|
63
|
+
<ToolbarGroup>
|
|
64
|
+
<ToolbarButton
|
|
65
|
+
name="view"
|
|
66
|
+
title={ __( 'View' ) }
|
|
67
|
+
onClick={ onViewPage }
|
|
68
|
+
>
|
|
69
|
+
{ __( 'View' ) }
|
|
70
|
+
</ToolbarButton>
|
|
71
|
+
</ToolbarGroup>
|
|
72
|
+
</BlockToolbarLastItem>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Higher-order component that adds the View button to navigation blocks.
|
|
78
|
+
*/
|
|
79
|
+
const withNavigationViewButton = createHigherOrderComponent(
|
|
80
|
+
( BlockEdit ) => ( props ) => {
|
|
81
|
+
const isSupportedBlock = SUPPORTED_BLOCKS.includes( props.name );
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
<>
|
|
85
|
+
<BlockEdit key="edit" { ...props } />
|
|
86
|
+
{ props.isSelected && isSupportedBlock && (
|
|
87
|
+
<NavigationViewButton { ...props } />
|
|
88
|
+
) }
|
|
89
|
+
</>
|
|
90
|
+
);
|
|
91
|
+
},
|
|
92
|
+
'withNavigationViewButton'
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
// Register the filter.
|
|
96
|
+
addFilter(
|
|
97
|
+
'editor.BlockEdit',
|
|
98
|
+
'core/editor/with-navigation-view-button',
|
|
99
|
+
withNavigationViewButton
|
|
100
|
+
);
|