@wordpress/edit-site 4.10.0 → 4.11.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/add-new-template/add-custom-template-modal.js +22 -42
- package/build/components/add-new-template/add-custom-template-modal.js.map +1 -1
- package/build/components/add-new-template/new-template.js +17 -20
- package/build/components/add-new-template/new-template.js.map +1 -1
- package/build/components/add-new-template/utils.js +366 -239
- package/build/components/add-new-template/utils.js.map +1 -1
- package/build/components/block-editor/index.js +1 -3
- package/build/components/block-editor/index.js.map +1 -1
- package/build/components/global-styles/dimensions-panel.js +183 -13
- package/build/components/global-styles/dimensions-panel.js.map +1 -1
- package/build/components/global-styles/hooks.js +1 -1
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/use-global-styles-output.js +95 -17
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/global-styles/utils.js +31 -0
- package/build/components/global-styles/utils.js.map +1 -1
- package/build/components/header/index.js +7 -6
- package/build/components/header/index.js.map +1 -1
- package/build/hooks/index.js +2 -0
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/template-part-edit.js +86 -0
- package/build/hooks/template-part-edit.js.map +1 -0
- package/build-module/components/add-new-template/add-custom-template-modal.js +23 -43
- package/build-module/components/add-new-template/add-custom-template-modal.js.map +1 -1
- package/build-module/components/add-new-template/new-template.js +18 -21
- package/build-module/components/add-new-template/new-template.js.map +1 -1
- package/build-module/components/add-new-template/utils.js +365 -227
- package/build-module/components/add-new-template/utils.js.map +1 -1
- package/build-module/components/block-editor/index.js +1 -2
- package/build-module/components/block-editor/index.js.map +1 -1
- package/build-module/components/global-styles/dimensions-panel.js +183 -14
- package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
- package/build-module/components/global-styles/hooks.js +1 -1
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js +94 -22
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/global-styles/utils.js +29 -0
- package/build-module/components/global-styles/utils.js.map +1 -1
- package/build-module/components/header/index.js +8 -6
- package/build-module/components/header/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/template-part-edit.js +67 -0
- package/build-module/hooks/template-part-edit.js.map +1 -0
- package/build-style/style-rtl.css +25 -25
- package/build-style/style.css +25 -25
- package/package.json +29 -29
- package/src/components/add-new-template/add-custom-template-modal.js +27 -45
- package/src/components/add-new-template/new-template.js +27 -64
- package/src/components/add-new-template/style.scss +20 -8
- package/src/components/add-new-template/utils.js +398 -229
- package/src/components/block-editor/index.js +0 -2
- package/src/components/global-styles/dimensions-panel.js +207 -14
- package/src/components/global-styles/hooks.js +2 -0
- package/src/components/global-styles/test/use-global-styles-output.js +64 -1
- package/src/components/global-styles/use-global-styles-output.js +100 -8
- package/src/components/global-styles/utils.js +31 -0
- package/src/components/header/index.js +9 -10
- package/src/components/header/style.scss +5 -3
- package/src/components/sidebar/style.scss +4 -0
- package/src/hooks/index.js +1 -0
- package/src/hooks/template-part-edit.js +82 -0
- package/src/style.scss +0 -1
- package/build/components/edit-template-part-menu-button/index.js +0 -90
- package/build/components/edit-template-part-menu-button/index.js.map +0 -1
- package/build-module/components/edit-template-part-menu-button/index.js +0 -72
- package/build-module/components/edit-template-part-menu-button/index.js.map +0 -1
- package/src/components/edit-template-part-menu-button/index.js +0 -82
|
@@ -226,15 +226,17 @@ body.is-navigation-sidebar-open {
|
|
|
226
226
|
padding-right: 6px;
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
-
// The
|
|
230
|
-
.edit-site-header-toolbar__inserter-toggle.edit-site-header-toolbar__inserter-toggle,
|
|
229
|
+
// The template details toggle has a custom label, different from its aria-label, so we don't want to display both.
|
|
231
230
|
.edit-site-document-actions__get-info.edit-site-document-actions__get-info.edit-site-document-actions__get-info {
|
|
232
231
|
&::after {
|
|
233
232
|
content: none;
|
|
234
233
|
}
|
|
234
|
+
}
|
|
235
235
|
|
|
236
|
+
.edit-site-header-toolbar__inserter-toggle.edit-site-header-toolbar__inserter-toggle,
|
|
237
|
+
.edit-site-document-actions__get-info.edit-site-document-actions__get-info.edit-site-document-actions__get-info {
|
|
236
238
|
height: 36px;
|
|
237
|
-
padding: 0
|
|
239
|
+
padding: 0 $grid-unit-10;
|
|
238
240
|
}
|
|
239
241
|
|
|
240
242
|
.edit-site-header_start .edit-site-header__toolbar > * + * {
|
|
@@ -60,6 +60,10 @@
|
|
|
60
60
|
grid-column: span 1;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
.edit-site-global-styles-sidebar .components-tools-panel .span-columns {
|
|
64
|
+
grid-column: 1 / -1;
|
|
65
|
+
}
|
|
66
|
+
|
|
63
67
|
.edit-site-global-styles-sidebar__blocks-group {
|
|
64
68
|
padding-top: $grid-unit-30;
|
|
65
69
|
border-top: $border-width solid $gray-200;
|
package/src/hooks/index.js
CHANGED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __ } from '@wordpress/i18n';
|
|
5
|
+
import { useSelect } from '@wordpress/data';
|
|
6
|
+
import { BlockControls } from '@wordpress/block-editor';
|
|
7
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
8
|
+
import { ToolbarButton } from '@wordpress/components';
|
|
9
|
+
import { addFilter } from '@wordpress/hooks';
|
|
10
|
+
import { createHigherOrderComponent } from '@wordpress/compose';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Internal dependencies
|
|
14
|
+
*/
|
|
15
|
+
import { useLocation } from '../components/routes';
|
|
16
|
+
import { useLink } from '../components/routes/link';
|
|
17
|
+
|
|
18
|
+
function EditTemplatePartMenuItem( { attributes } ) {
|
|
19
|
+
const { theme, slug } = attributes;
|
|
20
|
+
const { params } = useLocation();
|
|
21
|
+
const templatePart = useSelect(
|
|
22
|
+
( select ) => {
|
|
23
|
+
return select( coreStore ).getEntityRecord(
|
|
24
|
+
'postType',
|
|
25
|
+
'wp_template_part',
|
|
26
|
+
// Ideally this should be an official public API.
|
|
27
|
+
`${ theme }//${ slug }`
|
|
28
|
+
);
|
|
29
|
+
},
|
|
30
|
+
[ theme, slug ]
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
const linkProps = useLink(
|
|
34
|
+
{
|
|
35
|
+
postId: templatePart?.id,
|
|
36
|
+
postType: templatePart?.type,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
fromTemplateId: params.postId,
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
if ( ! templatePart ) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<BlockControls group="other">
|
|
49
|
+
<ToolbarButton
|
|
50
|
+
{ ...linkProps }
|
|
51
|
+
onClick={ ( event ) => {
|
|
52
|
+
linkProps.onClick( event );
|
|
53
|
+
} }
|
|
54
|
+
>
|
|
55
|
+
{ __( 'Edit' ) }
|
|
56
|
+
</ToolbarButton>
|
|
57
|
+
</BlockControls>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export const withEditBlockControls = createHigherOrderComponent(
|
|
62
|
+
( BlockEdit ) => ( props ) => {
|
|
63
|
+
const { attributes, name } = props;
|
|
64
|
+
const isDisplayed = name === 'core/template-part' && attributes.slug;
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<>
|
|
68
|
+
<BlockEdit { ...props } />
|
|
69
|
+
{ isDisplayed && (
|
|
70
|
+
<EditTemplatePartMenuItem attributes={ attributes } />
|
|
71
|
+
) }
|
|
72
|
+
</>
|
|
73
|
+
);
|
|
74
|
+
},
|
|
75
|
+
'withEditBlockControls'
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
addFilter(
|
|
79
|
+
'editor.BlockEdit',
|
|
80
|
+
'core/edit-site/template-part-edit-button',
|
|
81
|
+
withEditBlockControls
|
|
82
|
+
);
|
package/src/style.scss
CHANGED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.default = EditTemplatePartMenuButton;
|
|
9
|
-
|
|
10
|
-
var _element = require("@wordpress/element");
|
|
11
|
-
|
|
12
|
-
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
13
|
-
|
|
14
|
-
var _data = require("@wordpress/data");
|
|
15
|
-
|
|
16
|
-
var _blockEditor = require("@wordpress/block-editor");
|
|
17
|
-
|
|
18
|
-
var _coreData = require("@wordpress/core-data");
|
|
19
|
-
|
|
20
|
-
var _components = require("@wordpress/components");
|
|
21
|
-
|
|
22
|
-
var _blocks = require("@wordpress/blocks");
|
|
23
|
-
|
|
24
|
-
var _i18n = require("@wordpress/i18n");
|
|
25
|
-
|
|
26
|
-
var _routes = require("../routes");
|
|
27
|
-
|
|
28
|
-
var _link = require("../routes/link");
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* WordPress dependencies
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Internal dependencies
|
|
36
|
-
*/
|
|
37
|
-
function EditTemplatePartMenuButton() {
|
|
38
|
-
return (0, _element.createElement)(_blockEditor.BlockSettingsMenuControls, null, _ref => {
|
|
39
|
-
let {
|
|
40
|
-
selectedClientIds,
|
|
41
|
-
onClose
|
|
42
|
-
} = _ref;
|
|
43
|
-
return (0, _element.createElement)(EditTemplatePartMenuItem, {
|
|
44
|
-
selectedClientId: selectedClientIds[0],
|
|
45
|
-
onClose: onClose
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function EditTemplatePartMenuItem(_ref2) {
|
|
51
|
-
let {
|
|
52
|
-
selectedClientId,
|
|
53
|
-
onClose
|
|
54
|
-
} = _ref2;
|
|
55
|
-
const {
|
|
56
|
-
params
|
|
57
|
-
} = (0, _routes.useLocation)();
|
|
58
|
-
const selectedTemplatePart = (0, _data.useSelect)(select => {
|
|
59
|
-
const block = select(_blockEditor.store).getBlock(selectedClientId);
|
|
60
|
-
|
|
61
|
-
if (block && (0, _blocks.isTemplatePart)(block)) {
|
|
62
|
-
const {
|
|
63
|
-
theme,
|
|
64
|
-
slug
|
|
65
|
-
} = block.attributes;
|
|
66
|
-
return select(_coreData.store).getEntityRecord('postType', 'wp_template_part', // Ideally this should be an official public API.
|
|
67
|
-
`${theme}//${slug}`);
|
|
68
|
-
}
|
|
69
|
-
}, [selectedClientId]);
|
|
70
|
-
const linkProps = (0, _link.useLink)({
|
|
71
|
-
postId: selectedTemplatePart === null || selectedTemplatePart === void 0 ? void 0 : selectedTemplatePart.id,
|
|
72
|
-
postType: selectedTemplatePart === null || selectedTemplatePart === void 0 ? void 0 : selectedTemplatePart.type
|
|
73
|
-
}, {
|
|
74
|
-
fromTemplateId: params.postId
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
if (!selectedTemplatePart) {
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return (0, _element.createElement)(_components.MenuItem, (0, _extends2.default)({}, linkProps, {
|
|
82
|
-
onClick: event => {
|
|
83
|
-
linkProps.onClick(event);
|
|
84
|
-
onClose();
|
|
85
|
-
}
|
|
86
|
-
}),
|
|
87
|
-
/* translators: %s: template part title */
|
|
88
|
-
(0, _i18n.sprintf)((0, _i18n.__)('Edit %s'), selectedTemplatePart.slug));
|
|
89
|
-
}
|
|
90
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/components/edit-template-part-menu-button/index.js"],"names":["EditTemplatePartMenuButton","selectedClientIds","onClose","EditTemplatePartMenuItem","selectedClientId","params","selectedTemplatePart","select","block","blockEditorStore","getBlock","theme","slug","attributes","coreStore","getEntityRecord","linkProps","postId","id","postType","type","fromTemplateId","event","onClick"],"mappings":";;;;;;;;;;;;;AAGA;;AACA;;AAIA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAjBA;AACA;AACA;;AAWA;AACA;AACA;AAIe,SAASA,0BAAT,GAAsC;AACpD,SACC,4BAAC,sCAAD,QACG;AAAA,QAAE;AAAEC,MAAAA,iBAAF;AAAqBC,MAAAA;AAArB,KAAF;AAAA,WACD,4BAAC,wBAAD;AACC,MAAA,gBAAgB,EAAGD,iBAAiB,CAAE,CAAF,CADrC;AAEC,MAAA,OAAO,EAAGC;AAFX,MADC;AAAA,GADH,CADD;AAUA;;AAED,SAASC,wBAAT,QAAmE;AAAA,MAAhC;AAAEC,IAAAA,gBAAF;AAAoBF,IAAAA;AAApB,GAAgC;AAClE,QAAM;AAAEG,IAAAA;AAAF,MAAa,0BAAnB;AACA,QAAMC,oBAAoB,GAAG,qBAC1BC,MAAF,IAAc;AACb,UAAMC,KAAK,GACVD,MAAM,CAAEE,kBAAF,CAAN,CAA2BC,QAA3B,CAAqCN,gBAArC,CADD;;AAGA,QAAKI,KAAK,IAAI,4BAAgBA,KAAhB,CAAd,EAAwC;AACvC,YAAM;AAAEG,QAAAA,KAAF;AAASC,QAAAA;AAAT,UAAkBJ,KAAK,CAACK,UAA9B;AAEA,aAAON,MAAM,CAAEO,eAAF,CAAN,CAAoBC,eAApB,CACN,UADM,EAEN,kBAFM,EAGN;AACC,SAAGJ,KAAO,KAAKC,IAAM,EAJhB,CAAP;AAMA;AACD,GAf2B,EAgB5B,CAAER,gBAAF,CAhB4B,CAA7B;AAmBA,QAAMY,SAAS,GAAG,mBACjB;AACCC,IAAAA,MAAM,EAAEX,oBAAF,aAAEA,oBAAF,uBAAEA,oBAAoB,CAAEY,EAD/B;AAECC,IAAAA,QAAQ,EAAEb,oBAAF,aAAEA,oBAAF,uBAAEA,oBAAoB,CAAEc;AAFjC,GADiB,EAKjB;AACCC,IAAAA,cAAc,EAAEhB,MAAM,CAACY;AADxB,GALiB,CAAlB;;AAUA,MAAK,CAAEX,oBAAP,EAA8B;AAC7B,WAAO,IAAP;AACA;;AAED,SACC,4BAAC,oBAAD,6BACMU,SADN;AAEC,IAAA,OAAO,EAAKM,KAAF,IAAa;AACtBN,MAAAA,SAAS,CAACO,OAAV,CAAmBD,KAAnB;AACApB,MAAAA,OAAO;AACP;AALF;AAQE;AACA,qBAAS,cAAI,SAAJ,CAAT,EAA0BI,oBAAoB,CAACM,IAA/C,CATF,CADD;AAcA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport {\n\tstore as blockEditorStore,\n\tBlockSettingsMenuControls,\n} from '@wordpress/block-editor';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { MenuItem } from '@wordpress/components';\nimport { isTemplatePart } from '@wordpress/blocks';\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { useLocation } from '../routes';\nimport { useLink } from '../routes/link';\n\nexport default function EditTemplatePartMenuButton() {\n\treturn (\n\t\t<BlockSettingsMenuControls>\n\t\t\t{ ( { selectedClientIds, onClose } ) => (\n\t\t\t\t<EditTemplatePartMenuItem\n\t\t\t\t\tselectedClientId={ selectedClientIds[ 0 ] }\n\t\t\t\t\tonClose={ onClose }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</BlockSettingsMenuControls>\n\t);\n}\n\nfunction EditTemplatePartMenuItem( { selectedClientId, onClose } ) {\n\tconst { params } = useLocation();\n\tconst selectedTemplatePart = useSelect(\n\t\t( select ) => {\n\t\t\tconst block =\n\t\t\t\tselect( blockEditorStore ).getBlock( selectedClientId );\n\n\t\t\tif ( block && isTemplatePart( block ) ) {\n\t\t\t\tconst { theme, slug } = block.attributes;\n\n\t\t\t\treturn select( coreStore ).getEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'wp_template_part',\n\t\t\t\t\t// Ideally this should be an official public API.\n\t\t\t\t\t`${ theme }//${ slug }`\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t\t[ selectedClientId ]\n\t);\n\n\tconst linkProps = useLink(\n\t\t{\n\t\t\tpostId: selectedTemplatePart?.id,\n\t\t\tpostType: selectedTemplatePart?.type,\n\t\t},\n\t\t{\n\t\t\tfromTemplateId: params.postId,\n\t\t}\n\t);\n\n\tif ( ! selectedTemplatePart ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<MenuItem\n\t\t\t{ ...linkProps }\n\t\t\tonClick={ ( event ) => {\n\t\t\t\tlinkProps.onClick( event );\n\t\t\t\tonClose();\n\t\t\t} }\n\t\t>\n\t\t\t{\n\t\t\t\t/* translators: %s: template part title */\n\t\t\t\tsprintf( __( 'Edit %s' ), selectedTemplatePart.slug )\n\t\t\t}\n\t\t</MenuItem>\n\t);\n}\n"]}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import { createElement } from "@wordpress/element";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* WordPress dependencies
|
|
6
|
-
*/
|
|
7
|
-
import { useSelect } from '@wordpress/data';
|
|
8
|
-
import { store as blockEditorStore, BlockSettingsMenuControls } from '@wordpress/block-editor';
|
|
9
|
-
import { store as coreStore } from '@wordpress/core-data';
|
|
10
|
-
import { MenuItem } from '@wordpress/components';
|
|
11
|
-
import { isTemplatePart } from '@wordpress/blocks';
|
|
12
|
-
import { __, sprintf } from '@wordpress/i18n';
|
|
13
|
-
/**
|
|
14
|
-
* Internal dependencies
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import { useLocation } from '../routes';
|
|
18
|
-
import { useLink } from '../routes/link';
|
|
19
|
-
export default function EditTemplatePartMenuButton() {
|
|
20
|
-
return createElement(BlockSettingsMenuControls, null, _ref => {
|
|
21
|
-
let {
|
|
22
|
-
selectedClientIds,
|
|
23
|
-
onClose
|
|
24
|
-
} = _ref;
|
|
25
|
-
return createElement(EditTemplatePartMenuItem, {
|
|
26
|
-
selectedClientId: selectedClientIds[0],
|
|
27
|
-
onClose: onClose
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function EditTemplatePartMenuItem(_ref2) {
|
|
33
|
-
let {
|
|
34
|
-
selectedClientId,
|
|
35
|
-
onClose
|
|
36
|
-
} = _ref2;
|
|
37
|
-
const {
|
|
38
|
-
params
|
|
39
|
-
} = useLocation();
|
|
40
|
-
const selectedTemplatePart = useSelect(select => {
|
|
41
|
-
const block = select(blockEditorStore).getBlock(selectedClientId);
|
|
42
|
-
|
|
43
|
-
if (block && isTemplatePart(block)) {
|
|
44
|
-
const {
|
|
45
|
-
theme,
|
|
46
|
-
slug
|
|
47
|
-
} = block.attributes;
|
|
48
|
-
return select(coreStore).getEntityRecord('postType', 'wp_template_part', // Ideally this should be an official public API.
|
|
49
|
-
`${theme}//${slug}`);
|
|
50
|
-
}
|
|
51
|
-
}, [selectedClientId]);
|
|
52
|
-
const linkProps = useLink({
|
|
53
|
-
postId: selectedTemplatePart === null || selectedTemplatePart === void 0 ? void 0 : selectedTemplatePart.id,
|
|
54
|
-
postType: selectedTemplatePart === null || selectedTemplatePart === void 0 ? void 0 : selectedTemplatePart.type
|
|
55
|
-
}, {
|
|
56
|
-
fromTemplateId: params.postId
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
if (!selectedTemplatePart) {
|
|
60
|
-
return null;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return createElement(MenuItem, _extends({}, linkProps, {
|
|
64
|
-
onClick: event => {
|
|
65
|
-
linkProps.onClick(event);
|
|
66
|
-
onClose();
|
|
67
|
-
}
|
|
68
|
-
}),
|
|
69
|
-
/* translators: %s: template part title */
|
|
70
|
-
sprintf(__('Edit %s'), selectedTemplatePart.slug));
|
|
71
|
-
}
|
|
72
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/components/edit-template-part-menu-button/index.js"],"names":["useSelect","store","blockEditorStore","BlockSettingsMenuControls","coreStore","MenuItem","isTemplatePart","__","sprintf","useLocation","useLink","EditTemplatePartMenuButton","selectedClientIds","onClose","EditTemplatePartMenuItem","selectedClientId","params","selectedTemplatePart","select","block","getBlock","theme","slug","attributes","getEntityRecord","linkProps","postId","id","postType","type","fromTemplateId","event","onClick"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,iBAA1B;AACA,SACCC,KAAK,IAAIC,gBADV,EAECC,yBAFD,QAGO,yBAHP;AAIA,SAASF,KAAK,IAAIG,SAAlB,QAAmC,sBAAnC;AACA,SAASC,QAAT,QAAyB,uBAAzB;AACA,SAASC,cAAT,QAA+B,mBAA/B;AACA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AAEA;AACA;AACA;;AACA,SAASC,WAAT,QAA4B,WAA5B;AACA,SAASC,OAAT,QAAwB,gBAAxB;AAEA,eAAe,SAASC,0BAAT,GAAsC;AACpD,SACC,cAAC,yBAAD,QACG;AAAA,QAAE;AAAEC,MAAAA,iBAAF;AAAqBC,MAAAA;AAArB,KAAF;AAAA,WACD,cAAC,wBAAD;AACC,MAAA,gBAAgB,EAAGD,iBAAiB,CAAE,CAAF,CADrC;AAEC,MAAA,OAAO,EAAGC;AAFX,MADC;AAAA,GADH,CADD;AAUA;;AAED,SAASC,wBAAT,QAAmE;AAAA,MAAhC;AAAEC,IAAAA,gBAAF;AAAoBF,IAAAA;AAApB,GAAgC;AAClE,QAAM;AAAEG,IAAAA;AAAF,MAAaP,WAAW,EAA9B;AACA,QAAMQ,oBAAoB,GAAGjB,SAAS,CACnCkB,MAAF,IAAc;AACb,UAAMC,KAAK,GACVD,MAAM,CAAEhB,gBAAF,CAAN,CAA2BkB,QAA3B,CAAqCL,gBAArC,CADD;;AAGA,QAAKI,KAAK,IAAIb,cAAc,CAAEa,KAAF,CAA5B,EAAwC;AACvC,YAAM;AAAEE,QAAAA,KAAF;AAASC,QAAAA;AAAT,UAAkBH,KAAK,CAACI,UAA9B;AAEA,aAAOL,MAAM,CAAEd,SAAF,CAAN,CAAoBoB,eAApB,CACN,UADM,EAEN,kBAFM,EAGN;AACC,SAAGH,KAAO,KAAKC,IAAM,EAJhB,CAAP;AAMA;AACD,GAfoC,EAgBrC,CAAEP,gBAAF,CAhBqC,CAAtC;AAmBA,QAAMU,SAAS,GAAGf,OAAO,CACxB;AACCgB,IAAAA,MAAM,EAAET,oBAAF,aAAEA,oBAAF,uBAAEA,oBAAoB,CAAEU,EAD/B;AAECC,IAAAA,QAAQ,EAAEX,oBAAF,aAAEA,oBAAF,uBAAEA,oBAAoB,CAAEY;AAFjC,GADwB,EAKxB;AACCC,IAAAA,cAAc,EAAEd,MAAM,CAACU;AADxB,GALwB,CAAzB;;AAUA,MAAK,CAAET,oBAAP,EAA8B;AAC7B,WAAO,IAAP;AACA;;AAED,SACC,cAAC,QAAD,eACMQ,SADN;AAEC,IAAA,OAAO,EAAKM,KAAF,IAAa;AACtBN,MAAAA,SAAS,CAACO,OAAV,CAAmBD,KAAnB;AACAlB,MAAAA,OAAO;AACP;AALF;AAQE;AACAL,EAAAA,OAAO,CAAED,EAAE,CAAE,SAAF,CAAJ,EAAmBU,oBAAoB,CAACK,IAAxC,CATT,CADD;AAcA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport {\n\tstore as blockEditorStore,\n\tBlockSettingsMenuControls,\n} from '@wordpress/block-editor';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { MenuItem } from '@wordpress/components';\nimport { isTemplatePart } from '@wordpress/blocks';\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { useLocation } from '../routes';\nimport { useLink } from '../routes/link';\n\nexport default function EditTemplatePartMenuButton() {\n\treturn (\n\t\t<BlockSettingsMenuControls>\n\t\t\t{ ( { selectedClientIds, onClose } ) => (\n\t\t\t\t<EditTemplatePartMenuItem\n\t\t\t\t\tselectedClientId={ selectedClientIds[ 0 ] }\n\t\t\t\t\tonClose={ onClose }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</BlockSettingsMenuControls>\n\t);\n}\n\nfunction EditTemplatePartMenuItem( { selectedClientId, onClose } ) {\n\tconst { params } = useLocation();\n\tconst selectedTemplatePart = useSelect(\n\t\t( select ) => {\n\t\t\tconst block =\n\t\t\t\tselect( blockEditorStore ).getBlock( selectedClientId );\n\n\t\t\tif ( block && isTemplatePart( block ) ) {\n\t\t\t\tconst { theme, slug } = block.attributes;\n\n\t\t\t\treturn select( coreStore ).getEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'wp_template_part',\n\t\t\t\t\t// Ideally this should be an official public API.\n\t\t\t\t\t`${ theme }//${ slug }`\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t\t[ selectedClientId ]\n\t);\n\n\tconst linkProps = useLink(\n\t\t{\n\t\t\tpostId: selectedTemplatePart?.id,\n\t\t\tpostType: selectedTemplatePart?.type,\n\t\t},\n\t\t{\n\t\t\tfromTemplateId: params.postId,\n\t\t}\n\t);\n\n\tif ( ! selectedTemplatePart ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<MenuItem\n\t\t\t{ ...linkProps }\n\t\t\tonClick={ ( event ) => {\n\t\t\t\tlinkProps.onClick( event );\n\t\t\t\tonClose();\n\t\t\t} }\n\t\t>\n\t\t\t{\n\t\t\t\t/* translators: %s: template part title */\n\t\t\t\tsprintf( __( 'Edit %s' ), selectedTemplatePart.slug )\n\t\t\t}\n\t\t</MenuItem>\n\t);\n}\n"]}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { useSelect } from '@wordpress/data';
|
|
5
|
-
import {
|
|
6
|
-
store as blockEditorStore,
|
|
7
|
-
BlockSettingsMenuControls,
|
|
8
|
-
} from '@wordpress/block-editor';
|
|
9
|
-
import { store as coreStore } from '@wordpress/core-data';
|
|
10
|
-
import { MenuItem } from '@wordpress/components';
|
|
11
|
-
import { isTemplatePart } from '@wordpress/blocks';
|
|
12
|
-
import { __, sprintf } from '@wordpress/i18n';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Internal dependencies
|
|
16
|
-
*/
|
|
17
|
-
import { useLocation } from '../routes';
|
|
18
|
-
import { useLink } from '../routes/link';
|
|
19
|
-
|
|
20
|
-
export default function EditTemplatePartMenuButton() {
|
|
21
|
-
return (
|
|
22
|
-
<BlockSettingsMenuControls>
|
|
23
|
-
{ ( { selectedClientIds, onClose } ) => (
|
|
24
|
-
<EditTemplatePartMenuItem
|
|
25
|
-
selectedClientId={ selectedClientIds[ 0 ] }
|
|
26
|
-
onClose={ onClose }
|
|
27
|
-
/>
|
|
28
|
-
) }
|
|
29
|
-
</BlockSettingsMenuControls>
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function EditTemplatePartMenuItem( { selectedClientId, onClose } ) {
|
|
34
|
-
const { params } = useLocation();
|
|
35
|
-
const selectedTemplatePart = useSelect(
|
|
36
|
-
( select ) => {
|
|
37
|
-
const block =
|
|
38
|
-
select( blockEditorStore ).getBlock( selectedClientId );
|
|
39
|
-
|
|
40
|
-
if ( block && isTemplatePart( block ) ) {
|
|
41
|
-
const { theme, slug } = block.attributes;
|
|
42
|
-
|
|
43
|
-
return select( coreStore ).getEntityRecord(
|
|
44
|
-
'postType',
|
|
45
|
-
'wp_template_part',
|
|
46
|
-
// Ideally this should be an official public API.
|
|
47
|
-
`${ theme }//${ slug }`
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
[ selectedClientId ]
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
const linkProps = useLink(
|
|
55
|
-
{
|
|
56
|
-
postId: selectedTemplatePart?.id,
|
|
57
|
-
postType: selectedTemplatePart?.type,
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
fromTemplateId: params.postId,
|
|
61
|
-
}
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
if ( ! selectedTemplatePart ) {
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return (
|
|
69
|
-
<MenuItem
|
|
70
|
-
{ ...linkProps }
|
|
71
|
-
onClick={ ( event ) => {
|
|
72
|
-
linkProps.onClick( event );
|
|
73
|
-
onClose();
|
|
74
|
-
} }
|
|
75
|
-
>
|
|
76
|
-
{
|
|
77
|
-
/* translators: %s: template part title */
|
|
78
|
-
sprintf( __( 'Edit %s' ), selectedTemplatePart.slug )
|
|
79
|
-
}
|
|
80
|
-
</MenuItem>
|
|
81
|
-
);
|
|
82
|
-
}
|