@wordpress/edit-post 6.8.0 → 6.9.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.
Files changed (81) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/README.md +1 -1
  3. package/build/components/keyboard-shortcut-help-modal/config.js +12 -0
  4. package/build/components/keyboard-shortcut-help-modal/config.js.map +1 -1
  5. package/build/components/sidebar/plugin-post-status-info/index.js +2 -2
  6. package/build/components/sidebar/plugin-post-status-info/index.js.map +1 -1
  7. package/build/components/sidebar/post-schedule/index.js +6 -6
  8. package/build/components/sidebar/post-schedule/index.js.map +1 -1
  9. package/build/components/sidebar/post-status/index.js +4 -2
  10. package/build/components/sidebar/post-status/index.js.map +1 -1
  11. package/build/components/sidebar/post-template/create-modal.js +116 -0
  12. package/build/components/sidebar/post-template/create-modal.js.map +1 -0
  13. package/build/components/sidebar/post-template/form.js +123 -0
  14. package/build/components/sidebar/post-template/form.js.map +1 -0
  15. package/build/components/sidebar/post-template/index.js +123 -0
  16. package/build/components/sidebar/post-template/index.js.map +1 -0
  17. package/build/components/sidebar/settings-sidebar/index.js +1 -3
  18. package/build/components/sidebar/settings-sidebar/index.js.map +1 -1
  19. package/build/components/start-page-options/index.js +31 -13
  20. package/build/components/start-page-options/index.js.map +1 -1
  21. package/build/editor.js +1 -1
  22. package/build/editor.js.map +1 -1
  23. package/build/editor.native.js +1 -1
  24. package/build/editor.native.js.map +1 -1
  25. package/build/store/selectors.js +8 -8
  26. package/build/store/selectors.js.map +1 -1
  27. package/build-module/components/keyboard-shortcut-help-modal/config.js +12 -0
  28. package/build-module/components/keyboard-shortcut-help-modal/config.js.map +1 -1
  29. package/build-module/components/sidebar/plugin-post-status-info/index.js +2 -2
  30. package/build-module/components/sidebar/plugin-post-status-info/index.js.map +1 -1
  31. package/build-module/components/sidebar/post-schedule/index.js +7 -4
  32. package/build-module/components/sidebar/post-schedule/index.js.map +1 -1
  33. package/build-module/components/sidebar/post-status/index.js +3 -2
  34. package/build-module/components/sidebar/post-status/index.js.map +1 -1
  35. package/build-module/components/sidebar/post-template/create-modal.js +104 -0
  36. package/build-module/components/sidebar/post-template/create-modal.js.map +1 -0
  37. package/build-module/components/sidebar/post-template/form.js +106 -0
  38. package/build-module/components/sidebar/post-template/form.js.map +1 -0
  39. package/build-module/components/sidebar/post-template/index.js +109 -0
  40. package/build-module/components/sidebar/post-template/index.js.map +1 -0
  41. package/build-module/components/sidebar/settings-sidebar/index.js +1 -2
  42. package/build-module/components/sidebar/settings-sidebar/index.js.map +1 -1
  43. package/build-module/components/start-page-options/index.js +32 -14
  44. package/build-module/components/start-page-options/index.js.map +1 -1
  45. package/build-module/editor.js +2 -2
  46. package/build-module/editor.js.map +1 -1
  47. package/build-module/editor.native.js +2 -2
  48. package/build-module/editor.native.js.map +1 -1
  49. package/build-module/store/selectors.js +8 -7
  50. package/build-module/store/selectors.js.map +1 -1
  51. package/build-style/style-rtl.css +56 -44
  52. package/build-style/style.css +56 -44
  53. package/package.json +27 -27
  54. package/src/components/keyboard-shortcut-help-modal/config.js +8 -0
  55. package/src/components/keyboard-shortcut-help-modal/test/__snapshots__/index.js.snap +14 -0
  56. package/src/components/sidebar/plugin-post-status-info/index.js +2 -2
  57. package/src/components/sidebar/post-schedule/index.js +5 -3
  58. package/src/components/sidebar/post-schedule/style.scss +18 -3
  59. package/src/components/sidebar/post-status/index.js +3 -1
  60. package/src/components/sidebar/post-template/create-modal.js +146 -0
  61. package/src/components/sidebar/post-template/form.js +140 -0
  62. package/src/components/sidebar/post-template/index.js +101 -0
  63. package/src/components/sidebar/post-template/style.scss +46 -0
  64. package/src/components/sidebar/post-visibility/style.scss +4 -4
  65. package/src/components/sidebar/settings-sidebar/index.js +0 -2
  66. package/src/components/start-page-options/index.js +46 -22
  67. package/src/editor.js +2 -2
  68. package/src/editor.native.js +2 -2
  69. package/src/store/selectors.js +5 -8
  70. package/src/style.scss +1 -1
  71. package/build/components/sidebar/template/actions.js +0 -172
  72. package/build/components/sidebar/template/actions.js.map +0 -1
  73. package/build/components/sidebar/template/index.js +0 -164
  74. package/build/components/sidebar/template/index.js.map +0 -1
  75. package/build-module/components/sidebar/template/actions.js +0 -158
  76. package/build-module/components/sidebar/template/actions.js.map +0 -1
  77. package/build-module/components/sidebar/template/index.js +0 -145
  78. package/build-module/components/sidebar/template/index.js.map +0 -1
  79. package/src/components/sidebar/template/actions.js +0 -206
  80. package/src/components/sidebar/template/index.js +0 -160
  81. package/src/components/sidebar/template/style.scss +0 -43
@@ -1,158 +0,0 @@
1
- import { createElement, Fragment } from "@wordpress/element";
2
-
3
- /**
4
- * External dependencies
5
- */
6
- import { kebabCase } from 'lodash';
7
- /**
8
- * WordPress dependencies
9
- */
10
-
11
- import { __, _x, sprintf } from '@wordpress/i18n';
12
- import { Button, Modal, TextControl, Flex, FlexItem } from '@wordpress/components';
13
- import { useSelect, useDispatch } from '@wordpress/data';
14
- import { useState } from '@wordpress/element';
15
- import { store as editorStore } from '@wordpress/editor';
16
- import { store as coreStore } from '@wordpress/core-data';
17
- /**
18
- * Internal dependencies
19
- */
20
-
21
- import { store as editPostStore } from '../../../store';
22
- import { createBlock, serialize } from '@wordpress/blocks';
23
-
24
- function PostTemplateActions(_ref) {
25
- var _template$title$toLow;
26
-
27
- let {
28
- isPostsPage
29
- } = _ref;
30
- const [isModalOpen, setIsModalOpen] = useState(false);
31
- const [isBusy, setIsBusy] = useState(false);
32
- const [title, setTitle] = useState('');
33
- const {
34
- template,
35
- supportsTemplateMode,
36
- defaultTemplate
37
- } = useSelect(select => {
38
- var _getPostType$viewable, _getPostType;
39
-
40
- const {
41
- getCurrentPostType,
42
- getEditorSettings
43
- } = select(editorStore);
44
- const {
45
- getPostType
46
- } = select(coreStore);
47
- const {
48
- getEditedPostTemplate
49
- } = select(editPostStore);
50
- const isViewable = (_getPostType$viewable = (_getPostType = getPostType(getCurrentPostType())) === null || _getPostType === void 0 ? void 0 : _getPostType.viewable) !== null && _getPostType$viewable !== void 0 ? _getPostType$viewable : false;
51
-
52
- const _supportsTemplateMode = getEditorSettings().supportsTemplateMode && isViewable;
53
-
54
- return {
55
- template: _supportsTemplateMode && getEditedPostTemplate(),
56
- supportsTemplateMode: _supportsTemplateMode,
57
- defaultTemplate: getEditorSettings().defaultBlockTemplate
58
- };
59
- }, []);
60
- const {
61
- __unstableCreateTemplate,
62
- __unstableSwitchToTemplateMode
63
- } = useDispatch(editPostStore);
64
-
65
- if (!supportsTemplateMode) {
66
- return null;
67
- }
68
-
69
- const defaultTitle = __('Custom Template');
70
-
71
- async function onCreateTemplate(event) {
72
- event.preventDefault();
73
-
74
- if (isBusy) {
75
- return;
76
- }
77
-
78
- setIsBusy(true);
79
- const newTemplateContent = defaultTemplate !== null && defaultTemplate !== void 0 ? defaultTemplate : serialize([createBlock('core/group', {
80
- tagName: 'header',
81
- layout: {
82
- inherit: true
83
- }
84
- }, [createBlock('core/site-title'), createBlock('core/site-tagline')]), createBlock('core/separator'), createBlock('core/group', {
85
- tagName: 'main'
86
- }, [createBlock('core/group', {
87
- layout: {
88
- inherit: true
89
- }
90
- }, [createBlock('core/post-title')]), createBlock('core/post-content', {
91
- layout: {
92
- inherit: true
93
- }
94
- })])]);
95
- await __unstableCreateTemplate({
96
- slug: 'wp-custom-template-' + kebabCase(title || defaultTitle),
97
- content: newTemplateContent,
98
- title: title || defaultTitle
99
- });
100
- setIsBusy(false);
101
- setIsModalOpen(false);
102
-
103
- __unstableSwitchToTemplateMode(true);
104
- }
105
-
106
- return createElement(Fragment, null, createElement("div", {
107
- className: "edit-post-template__actions"
108
- }, !!template && createElement(Button, {
109
- variant: "link",
110
- onClick: () => __unstableSwitchToTemplateMode(),
111
- label: sprintf( // Translators: 1: The title or the slug of the currently selected template.
112
- __('Edit template: %s'), (_template$title$toLow = template === null || template === void 0 ? void 0 : template.title.toLowerCase()) !== null && _template$title$toLow !== void 0 ? _template$title$toLow : template.slug)
113
- }, __('Edit')), !isPostsPage && createElement(Button, {
114
- variant: "link",
115
- onClick: () => setIsModalOpen(true),
116
- label: _x('New template', 'action')
117
- },
118
- /* translators: button to create a new template */
119
- _x('New', 'action'))), isModalOpen && createElement(Modal, {
120
- title: __('Create custom template'),
121
- closeLabel: __('Close'),
122
- onRequestClose: () => {
123
- setIsModalOpen(false);
124
- setTitle('');
125
- },
126
- overlayClassName: "edit-post-template__modal"
127
- }, createElement("form", {
128
- onSubmit: onCreateTemplate
129
- }, createElement(Flex, {
130
- align: "flex-start",
131
- gap: 8
132
- }, createElement(FlexItem, null, createElement(TextControl, {
133
- label: __('Name'),
134
- value: title,
135
- onChange: setTitle,
136
- placeholder: defaultTitle,
137
- disabled: isBusy,
138
- help: __('Describe the purpose of the template, e.g. "Full Width". Custom templates can be applied to any post or page.')
139
- }))), createElement(Flex, {
140
- className: "edit-post-template__modal-actions",
141
- justify: "flex-end",
142
- expanded: false
143
- }, createElement(FlexItem, null, createElement(Button, {
144
- variant: "tertiary",
145
- onClick: () => {
146
- setIsModalOpen(false);
147
- setTitle('');
148
- }
149
- }, __('Cancel'))), createElement(FlexItem, null, createElement(Button, {
150
- variant: "primary",
151
- type: "submit",
152
- isBusy: isBusy,
153
- "aria-disabled": isBusy
154
- }, __('Create')))))));
155
- }
156
-
157
- export default PostTemplateActions;
158
- //# sourceMappingURL=actions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["@wordpress/edit-post/src/components/sidebar/template/actions.js"],"names":["kebabCase","__","_x","sprintf","Button","Modal","TextControl","Flex","FlexItem","useSelect","useDispatch","useState","store","editorStore","coreStore","editPostStore","createBlock","serialize","PostTemplateActions","isPostsPage","isModalOpen","setIsModalOpen","isBusy","setIsBusy","title","setTitle","template","supportsTemplateMode","defaultTemplate","select","getCurrentPostType","getEditorSettings","getPostType","getEditedPostTemplate","isViewable","viewable","_supportsTemplateMode","defaultBlockTemplate","__unstableCreateTemplate","__unstableSwitchToTemplateMode","defaultTitle","onCreateTemplate","event","preventDefault","newTemplateContent","tagName","layout","inherit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MAAM;AACtBoB,MAAAA,cAAc,CAAE,KAAF,CAAd;AACAI,MAAAA,QAAQ,CAAE,EAAF,CAAR;AACA,KANF;AAOC,IAAA,gBAAgB,EAAC;AAPlB,KASC;AAAM,IAAA,QAAQ,EAAGgB;AAAjB,KACC,cAAC,IAAD;AAAM,IAAA,KAAK,EAAC,YAAZ;AAAyB,IAAA,GAAG,EAAG;AAA/B,KACC,cAAC,QAAD,QACC,cAAC,WAAD;AACC,IAAA,KAAK,EAAGxC,EAAE,CAAE,MAAF,CADX;AAEC,IAAA,KAAK,EAAGuB,KAFT;AAGC,IAAA,QAAQ,EAAGC,QAHZ;AAIC,IAAA,WAAW,EAAGe,YAJf;AAKC,IAAA,QAAQ,EAAGlB,MALZ;AAMC,IAAA,IAAI,EAAGrB,EAAE,CACR,+GADQ;AANV,IADD,CADD,CADD,EAgBC,cAAC,IAAD;AACC,IAAA,SAAS,EAAC,mCADX;AAEC,IAAA,OAAO,EAAC,UAFT;AAGC,IAAA,QAAQ,EAAG;AAHZ,KAKC,cAAC,QAAD,QACC,cAAC,MAAD;AACC,IAAA,OAAO,EAAC,UADT;AAEC,IAAA,OAAO,EAAG,MAAM;AACfoB,MAAAA,cAAc,CAAE,KAAF,CAAd;AACAI,MAAAA,QAAQ,CAAE,EAAF,CAAR;AACA;AALF,KAOGxB,EAAE,CAAE,QAAF,CAPL,CADD,CALD,EAgBC,cAAC,QAAD,QACC,cAAC,MAAD;AACC,IAAA,OAAO,EAAC,SADT;AAEC,IAAA,IAAI,EAAC,QAFN;AAGC,IAAA,MAAM,EAAGqB,MAHV;AAIC,qBAAgBA;AAJjB,KAMGrB,EAAE,CAAE,QAAF,CANL,CADD,CAhBD,CAhBD,CATD,CA7BF,CADD;AAuFA;;AAED,eAAeiB,mBAAf","sourcesContent":["/**\n * External dependencies\n */\nimport { kebabCase } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport {\n\tButton,\n\tModal,\n\tTextControl,\n\tFlex,\n\tFlexItem,\n} from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useState } 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 { store as editPostStore } from '../../../store';\nimport { createBlock, serialize } from '@wordpress/blocks';\n\nfunction PostTemplateActions( { isPostsPage } ) {\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\tconst [ isBusy, setIsBusy ] = useState( false );\n\tconst [ title, setTitle ] = useState( '' );\n\tconst { template, supportsTemplateMode, defaultTemplate } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getCurrentPostType, getEditorSettings } =\n\t\t\t\tselect( editorStore );\n\t\t\tconst { getPostType } = select( coreStore );\n\t\t\tconst { getEditedPostTemplate } = select( editPostStore );\n\n\t\t\tconst isViewable =\n\t\t\t\tgetPostType( getCurrentPostType() )?.viewable ?? false;\n\t\t\tconst _supportsTemplateMode =\n\t\t\t\tgetEditorSettings().supportsTemplateMode && isViewable;\n\n\t\t\treturn {\n\t\t\t\ttemplate: _supportsTemplateMode && getEditedPostTemplate(),\n\t\t\t\tsupportsTemplateMode: _supportsTemplateMode,\n\t\t\t\tdefaultTemplate: getEditorSettings().defaultBlockTemplate,\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\tconst { __unstableCreateTemplate, __unstableSwitchToTemplateMode } =\n\t\tuseDispatch( editPostStore );\n\n\tif ( ! supportsTemplateMode ) {\n\t\treturn null;\n\t}\n\n\tconst defaultTitle = __( 'Custom Template' );\n\n\tasync function onCreateTemplate( event ) {\n\t\tevent.preventDefault();\n\n\t\tif ( isBusy ) {\n\t\t\treturn;\n\t\t}\n\n\t\tsetIsBusy( true );\n\n\t\tconst newTemplateContent =\n\t\t\tdefaultTemplate ??\n\t\t\tserialize( [\n\t\t\t\tcreateBlock(\n\t\t\t\t\t'core/group',\n\t\t\t\t\t{\n\t\t\t\t\t\ttagName: 'header',\n\t\t\t\t\t\tlayout: { inherit: true },\n\t\t\t\t\t},\n\t\t\t\t\t[\n\t\t\t\t\t\tcreateBlock( 'core/site-title' ),\n\t\t\t\t\t\tcreateBlock( 'core/site-tagline' ),\n\t\t\t\t\t]\n\t\t\t\t),\n\t\t\t\tcreateBlock( 'core/separator' ),\n\t\t\t\tcreateBlock(\n\t\t\t\t\t'core/group',\n\t\t\t\t\t{\n\t\t\t\t\t\ttagName: 'main',\n\t\t\t\t\t},\n\t\t\t\t\t[\n\t\t\t\t\t\tcreateBlock(\n\t\t\t\t\t\t\t'core/group',\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tlayout: { inherit: true },\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t[ createBlock( 'core/post-title' ) ]\n\t\t\t\t\t\t),\n\t\t\t\t\t\tcreateBlock( 'core/post-content', {\n\t\t\t\t\t\t\tlayout: { inherit: true },\n\t\t\t\t\t\t} ),\n\t\t\t\t\t]\n\t\t\t\t),\n\t\t\t] );\n\n\t\tawait __unstableCreateTemplate( {\n\t\t\tslug: 'wp-custom-template-' + kebabCase( title || defaultTitle ),\n\t\t\tcontent: newTemplateContent,\n\t\t\ttitle: title || defaultTitle,\n\t\t} );\n\n\t\tsetIsBusy( false );\n\t\tsetIsModalOpen( false );\n\n\t\t__unstableSwitchToTemplateMode( true );\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<div className=\"edit-post-template__actions\">\n\t\t\t\t{ !! template && (\n\t\t\t\t\t<Button\n\t\t\t\t\t\tvariant=\"link\"\n\t\t\t\t\t\tonClick={ () => __unstableSwitchToTemplateMode() }\n\t\t\t\t\t\tlabel={ sprintf(\n\t\t\t\t\t\t\t// Translators: 1: The title or the slug of the currently selected template.\n\t\t\t\t\t\t\t__( 'Edit template: %s' ),\n\t\t\t\t\t\t\ttemplate?.title.toLowerCase() ?? template.slug\n\t\t\t\t\t\t) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Edit' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t) }\n\t\t\t\t{ ! isPostsPage && (\n\t\t\t\t\t<Button\n\t\t\t\t\t\tvariant=\"link\"\n\t\t\t\t\t\tonClick={ () => setIsModalOpen( true ) }\n\t\t\t\t\t\tlabel={ _x( 'New template', 'action' ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t/* translators: button to create a new template */\n\t\t\t\t\t\t\t_x( 'New', 'action' )\n\t\t\t\t\t\t}\n\t\t\t\t\t</Button>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t\t{ isModalOpen && (\n\t\t\t\t<Modal\n\t\t\t\t\ttitle={ __( 'Create custom template' ) }\n\t\t\t\t\tcloseLabel={ __( 'Close' ) }\n\t\t\t\t\tonRequestClose={ () => {\n\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t} }\n\t\t\t\t\toverlayClassName=\"edit-post-template__modal\"\n\t\t\t\t>\n\t\t\t\t\t<form onSubmit={ onCreateTemplate }>\n\t\t\t\t\t\t<Flex align=\"flex-start\" gap={ 8 }>\n\t\t\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\t\t\t\tplaceholder={ defaultTitle }\n\t\t\t\t\t\t\t\t\tdisabled={ isBusy }\n\t\t\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t\t\t'Describe the purpose of the template, e.g. \"Full Width\". Custom templates can be applied to any post or page.'\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t</Flex>\n\n\t\t\t\t\t\t<Flex\n\t\t\t\t\t\t\tclassName=\"edit-post-template__modal-actions\"\n\t\t\t\t\t\t\tjustify=\"flex-end\"\n\t\t\t\t\t\t\texpanded={ false }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\t\t\tisBusy={ isBusy }\n\t\t\t\t\t\t\t\t\taria-disabled={ isBusy }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Create' ) }\n\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t</Flex>\n\t\t\t\t\t</form>\n\t\t\t\t</Modal>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport default PostTemplateActions;\n"]}
@@ -1,145 +0,0 @@
1
- import { createElement } from "@wordpress/element";
2
-
3
- /**
4
- * External dependencies
5
- */
6
- import { partial, isEmpty, map, fromPairs } from 'lodash';
7
- /**
8
- * WordPress dependencies
9
- */
10
-
11
- import { __, sprintf } from '@wordpress/i18n';
12
- import { useMemo } from '@wordpress/element';
13
- import { Notice, PanelBody, SelectControl } from '@wordpress/components';
14
- import { store as editorStore } from '@wordpress/editor';
15
- import { useSelect, useDispatch } from '@wordpress/data';
16
- import { store as coreStore } from '@wordpress/core-data';
17
- /**
18
- * Internal dependencies
19
- */
20
-
21
- import PostTemplateActions from './actions';
22
- import { store as editPostStore } from '../../../store';
23
- /**
24
- * Module Constants
25
- */
26
-
27
- const PANEL_NAME = 'template';
28
- export function TemplatePanel() {
29
- const {
30
- isEnabled,
31
- isOpened,
32
- isPostsPage,
33
- selectedTemplate,
34
- availableTemplates,
35
- fetchedTemplates,
36
- isViewable,
37
- template,
38
- supportsTemplateMode,
39
- canUserCreate
40
- } = useSelect(select => {
41
- var _getPostType$viewable, _getPostType;
42
-
43
- const {
44
- isEditorPanelEnabled,
45
- isEditorPanelOpened,
46
- getEditedPostTemplate
47
- } = select(editPostStore);
48
- const {
49
- getEditedPostAttribute,
50
- getEditorSettings,
51
- getCurrentPostId,
52
- getCurrentPostType
53
- } = select(editorStore);
54
- const {
55
- getPostType,
56
- getEntityRecord,
57
- getEntityRecords,
58
- canUser
59
- } = select(coreStore);
60
- const currentPostId = getCurrentPostId();
61
- const currentPostType = getCurrentPostType();
62
- const settings = getEntityRecord('root', 'site');
63
-
64
- const _isViewable = (_getPostType$viewable = (_getPostType = getPostType(currentPostType)) === null || _getPostType === void 0 ? void 0 : _getPostType.viewable) !== null && _getPostType$viewable !== void 0 ? _getPostType$viewable : false;
65
-
66
- const _supportsTemplateMode = select(editorStore).getEditorSettings().supportsTemplateMode && _isViewable;
67
-
68
- const templateRecords = getEntityRecords('postType', 'wp_template', {
69
- post_type: currentPostType,
70
- per_page: -1
71
- });
72
- return {
73
- isEnabled: isEditorPanelEnabled(PANEL_NAME),
74
- isOpened: isEditorPanelOpened(PANEL_NAME),
75
- isPostsPage: currentPostId === (settings === null || settings === void 0 ? void 0 : settings.page_for_posts),
76
- selectedTemplate: getEditedPostAttribute('template'),
77
- availableTemplates: getEditorSettings().availableTemplates,
78
- fetchedTemplates: templateRecords,
79
- template: _supportsTemplateMode && getEditedPostTemplate(),
80
- isViewable: _isViewable,
81
- supportsTemplateMode: _supportsTemplateMode,
82
- canUserCreate: canUser('create', 'templates')
83
- };
84
- }, []);
85
- const templates = useMemo(() => {
86
- return { ...availableTemplates,
87
- ...fromPairs((fetchedTemplates !== null && fetchedTemplates !== void 0 ? fetchedTemplates : []).map(_ref => {
88
- let {
89
- slug,
90
- title
91
- } = _ref;
92
- return [slug, title.rendered];
93
- }))
94
- };
95
- }, [availableTemplates, fetchedTemplates]);
96
- const {
97
- toggleEditorPanelOpened
98
- } = useDispatch(editPostStore);
99
- const {
100
- editPost
101
- } = useDispatch(editorStore);
102
-
103
- if (!isEnabled || !isViewable || isEmpty(availableTemplates) && (!supportsTemplateMode || !canUserCreate)) {
104
- return null;
105
- }
106
-
107
- const onTogglePanel = partial(toggleEditorPanelOpened, PANEL_NAME);
108
-
109
- let panelTitle = __('Template');
110
-
111
- if (!!template) {
112
- var _template$title;
113
-
114
- panelTitle = sprintf(
115
- /* translators: %s: template title */
116
- __('Template: %s'), (_template$title = template === null || template === void 0 ? void 0 : template.title) !== null && _template$title !== void 0 ? _template$title : template.slug);
117
- }
118
-
119
- return createElement(PanelBody, {
120
- title: panelTitle,
121
- opened: isOpened,
122
- onToggle: onTogglePanel
123
- }, isPostsPage ? createElement(Notice, {
124
- className: "edit-post-template__notice",
125
- status: "warning",
126
- isDismissible: false
127
- }, __('The posts page template cannot be changed.')) : createElement(SelectControl, {
128
- hideLabelFromVision: true,
129
- label: __('Template:'),
130
- value: Object.keys(templates).includes(selectedTemplate) ? selectedTemplate : '',
131
- onChange: templateSlug => {
132
- editPost({
133
- template: templateSlug || ''
134
- });
135
- },
136
- options: map(templates, (templateName, templateSlug) => ({
137
- value: templateSlug,
138
- label: templateName
139
- }))
140
- }), canUserCreate && createElement(PostTemplateActions, {
141
- isPostsPage: isPostsPage
142
- }));
143
- }
144
- export default TemplatePanel;
145
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["@wordpress/edit-post/src/components/sidebar/template/index.js"],"names":["partial","isEmpty","map","fromPairs","__","sprintf","useMemo","Notice","PanelBody","SelectControl","store","editorStore","useSelect","useDispatch","coreStore","PostTemplateActions","editPostStore","PANEL_NAME","TemplatePanel","isEnabled","isOpened","isPostsPage","selectedTemplate","availableTemplates","fetchedTemplates","isViewable","template","supportsTemplateMode","canUserCreate","select","isEditorPanelEnabled","isEditorPanelOpened","getEditedPostTemplate","getEditedPostAttribute","getEditorSettings","getCurrentPostId","getCurrentPostType","getPostType","getEntityRecord","getEntityRecords","canUser","currentPostId","currentPostType","settings","_isViewable","viewable","_supportsTemplateMode","templateRecords","post_type","per_page","page_for_posts","templates","slug","title","rendered","toggleEditorPanelOpened","editPost","onTogglePanel","panelTitle","Object","keys","includes","templateSlug","templateName","value","label"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,OAAT,EAAkBC,OAAlB,EAA2BC,GAA3B,EAAgCC,SAAhC,QAAiD,QAAjD;AAEA;AACA;AACA;;AACA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,OAAT,QAAwB,oBAAxB;AACA,SAASC,MAAT,EAAiBC,SAAjB,EAA4BC,aAA5B,QAAiD,uBAAjD;AACA,SAASC,KAAK,IAAIC,WAAlB,QAAqC,mBAArC;AACA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASH,KAAK,IAAII,SAAlB,QAAmC,sBAAnC;AAEA;AACA;AACA;;AACA,OAAOC,mBAAP,MAAgC,WAAhC;AACA,SAASL,KAAK,IAAIM,aAAlB,QAAuC,gBAAvC;AAEA;AACA;AACA;;AACA,MAAMC,UAAU,GAAG,UAAnB;AAEA,OAAO,SAASC,aAAT,GAAyB;AAC/B,QAAM;AACLC,IAAAA,SADK;AAELC,IAAAA,QAFK;AAGLC,IAAAA,WAHK;AAILC,IAAAA,gBAJK;AAKLC,IAAAA,kBALK;AAMLC,IAAAA,gBANK;AAOLC,IAAAA,UAPK;AAQLC,IAAAA,QARK;AASLC,IAAAA,oBATK;AAULC,IAAAA;AAVK,MAWFhB,SAAS,CAAIiB,MAAF,IAAc;AAAA;;AAC5B,UAAM;AACLC,MAAAA,oB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GA3B,QAAQ,CAAC0B,IAHT,CAApB;AAKA;;AAED,SACC,cAAC,SAAD;AACC,IAAA,KAAK,EAAGM,UADT;AAEC,IAAA,MAAM,EAAGtC,QAFV;AAGC,IAAA,QAAQ,EAAGqC;AAHZ,KAKGpC,WAAW,GACZ,cAAC,MAAD;AACC,IAAA,SAAS,EAAC,4BADX;AAEC,IAAA,MAAM,EAAC,SAFR;AAGC,IAAA,aAAa,EAAG;AAHjB,KAKGjB,EAAE,CAAE,4CAAF,CALL,CADY,GASZ,cAAC,aAAD;AACC,IAAA,mBAAmB,MADpB;AAEC,IAAA,KAAK,EAAGA,EAAE,CAAE,WAAF,CAFX;AAGC,IAAA,KAAK,EACJuD,MAAM,CAACC,IAAP,CAAaT,SAAb,EAAyBU,QAAzB,CAAmCvC,gBAAnC,IACGA,gBADH,GAEG,EANL;AAQC,IAAA,QAAQ,EAAKwC,YAAF,IAAoB;AAC9BN,MAAAA,QAAQ,CAAE;AACT9B,QAAAA,QAAQ,EAAEoC,YAAY,IAAI;AADjB,OAAF,CAAR;AAGA,KAZF;AAaC,IAAA,OAAO,EAAG5D,GAAG,CACZiD,SADY,EAEZ,CAAEY,YAAF,EAAgBD,YAAhB,MAAoC;AACnCE,MAAAA,KAAK,EAAEF,YAD4B;AAEnCG,MAAAA,KAAK,EAAEF;AAF4B,KAApC,CAFY;AAbd,IAdF,EAoCGnC,aAAa,IACd,cAAC,mBAAD;AAAqB,IAAA,WAAW,EAAGP;AAAnC,IArCF,CADD;AA0CA;AAED,eAAeH,aAAf","sourcesContent":["/**\n * External dependencies\n */\nimport { partial, isEmpty, map, fromPairs } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useMemo } from '@wordpress/element';\nimport { Notice, PanelBody, SelectControl } from '@wordpress/components';\nimport { store as editorStore } from '@wordpress/editor';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport PostTemplateActions from './actions';\nimport { store as editPostStore } from '../../../store';\n\n/**\n * Module Constants\n */\nconst PANEL_NAME = 'template';\n\nexport function TemplatePanel() {\n\tconst {\n\t\tisEnabled,\n\t\tisOpened,\n\t\tisPostsPage,\n\t\tselectedTemplate,\n\t\tavailableTemplates,\n\t\tfetchedTemplates,\n\t\tisViewable,\n\t\ttemplate,\n\t\tsupportsTemplateMode,\n\t\tcanUserCreate,\n\t} = useSelect( ( select ) => {\n\t\tconst {\n\t\t\tisEditorPanelEnabled,\n\t\t\tisEditorPanelOpened,\n\t\t\tgetEditedPostTemplate,\n\t\t} = select( editPostStore );\n\t\tconst {\n\t\t\tgetEditedPostAttribute,\n\t\t\tgetEditorSettings,\n\t\t\tgetCurrentPostId,\n\t\t\tgetCurrentPostType,\n\t\t} = select( editorStore );\n\t\tconst { getPostType, getEntityRecord, getEntityRecords, canUser } =\n\t\t\tselect( coreStore );\n\n\t\tconst currentPostId = getCurrentPostId();\n\t\tconst currentPostType = getCurrentPostType();\n\t\tconst settings = getEntityRecord( 'root', 'site' );\n\t\tconst _isViewable = getPostType( currentPostType )?.viewable ?? false;\n\t\tconst _supportsTemplateMode =\n\t\t\tselect( editorStore ).getEditorSettings().supportsTemplateMode &&\n\t\t\t_isViewable;\n\n\t\tconst templateRecords = getEntityRecords( 'postType', 'wp_template', {\n\t\t\tpost_type: currentPostType,\n\t\t\tper_page: -1,\n\t\t} );\n\n\t\treturn {\n\t\t\tisEnabled: isEditorPanelEnabled( PANEL_NAME ),\n\t\t\tisOpened: isEditorPanelOpened( PANEL_NAME ),\n\t\t\tisPostsPage: currentPostId === settings?.page_for_posts,\n\t\t\tselectedTemplate: getEditedPostAttribute( 'template' ),\n\t\t\tavailableTemplates: getEditorSettings().availableTemplates,\n\t\t\tfetchedTemplates: templateRecords,\n\t\t\ttemplate: _supportsTemplateMode && getEditedPostTemplate(),\n\t\t\tisViewable: _isViewable,\n\t\t\tsupportsTemplateMode: _supportsTemplateMode,\n\t\t\tcanUserCreate: canUser( 'create', 'templates' ),\n\t\t};\n\t}, [] );\n\n\tconst templates = useMemo( () => {\n\t\treturn {\n\t\t\t...availableTemplates,\n\t\t\t...fromPairs(\n\t\t\t\t( fetchedTemplates ?? [] ).map( ( { slug, title } ) => [\n\t\t\t\t\tslug,\n\t\t\t\t\ttitle.rendered,\n\t\t\t\t] )\n\t\t\t),\n\t\t};\n\t}, [ availableTemplates, fetchedTemplates ] );\n\n\tconst { toggleEditorPanelOpened } = useDispatch( editPostStore );\n\tconst { editPost } = useDispatch( editorStore );\n\n\tif (\n\t\t! isEnabled ||\n\t\t! isViewable ||\n\t\t( isEmpty( availableTemplates ) &&\n\t\t\t( ! supportsTemplateMode || ! canUserCreate ) )\n\t) {\n\t\treturn null;\n\t}\n\n\tconst onTogglePanel = partial( toggleEditorPanelOpened, PANEL_NAME );\n\n\tlet panelTitle = __( 'Template' );\n\tif ( !! template ) {\n\t\tpanelTitle = sprintf(\n\t\t\t/* translators: %s: template title */\n\t\t\t__( 'Template: %s' ),\n\t\t\ttemplate?.title ?? template.slug\n\t\t);\n\t}\n\n\treturn (\n\t\t<PanelBody\n\t\t\ttitle={ panelTitle }\n\t\t\topened={ isOpened }\n\t\t\tonToggle={ onTogglePanel }\n\t\t>\n\t\t\t{ isPostsPage ? (\n\t\t\t\t<Notice\n\t\t\t\t\tclassName=\"edit-post-template__notice\"\n\t\t\t\t\tstatus=\"warning\"\n\t\t\t\t\tisDismissible={ false }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'The posts page template cannot be changed.' ) }\n\t\t\t\t</Notice>\n\t\t\t) : (\n\t\t\t\t<SelectControl\n\t\t\t\t\thideLabelFromVision\n\t\t\t\t\tlabel={ __( 'Template:' ) }\n\t\t\t\t\tvalue={\n\t\t\t\t\t\tObject.keys( templates ).includes( selectedTemplate )\n\t\t\t\t\t\t\t? selectedTemplate\n\t\t\t\t\t\t\t: ''\n\t\t\t\t\t}\n\t\t\t\t\tonChange={ ( templateSlug ) => {\n\t\t\t\t\t\teditPost( {\n\t\t\t\t\t\t\ttemplate: templateSlug || '',\n\t\t\t\t\t\t} );\n\t\t\t\t\t} }\n\t\t\t\t\toptions={ map(\n\t\t\t\t\t\ttemplates,\n\t\t\t\t\t\t( templateName, templateSlug ) => ( {\n\t\t\t\t\t\t\tvalue: templateSlug,\n\t\t\t\t\t\t\tlabel: templateName,\n\t\t\t\t\t\t} )\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ canUserCreate && (\n\t\t\t\t<PostTemplateActions isPostsPage={ isPostsPage } />\n\t\t\t) }\n\t\t</PanelBody>\n\t);\n}\n\nexport default TemplatePanel;\n"]}
@@ -1,206 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { kebabCase } from 'lodash';
5
-
6
- /**
7
- * WordPress dependencies
8
- */
9
- import { __, _x, sprintf } from '@wordpress/i18n';
10
- import {
11
- Button,
12
- Modal,
13
- TextControl,
14
- Flex,
15
- FlexItem,
16
- } from '@wordpress/components';
17
- import { useSelect, useDispatch } from '@wordpress/data';
18
- import { useState } from '@wordpress/element';
19
- import { store as editorStore } from '@wordpress/editor';
20
- import { store as coreStore } from '@wordpress/core-data';
21
-
22
- /**
23
- * Internal dependencies
24
- */
25
- import { store as editPostStore } from '../../../store';
26
- import { createBlock, serialize } from '@wordpress/blocks';
27
-
28
- function PostTemplateActions( { isPostsPage } ) {
29
- const [ isModalOpen, setIsModalOpen ] = useState( false );
30
- const [ isBusy, setIsBusy ] = useState( false );
31
- const [ title, setTitle ] = useState( '' );
32
- const { template, supportsTemplateMode, defaultTemplate } = useSelect(
33
- ( select ) => {
34
- const { getCurrentPostType, getEditorSettings } =
35
- select( editorStore );
36
- const { getPostType } = select( coreStore );
37
- const { getEditedPostTemplate } = select( editPostStore );
38
-
39
- const isViewable =
40
- getPostType( getCurrentPostType() )?.viewable ?? false;
41
- const _supportsTemplateMode =
42
- getEditorSettings().supportsTemplateMode && isViewable;
43
-
44
- return {
45
- template: _supportsTemplateMode && getEditedPostTemplate(),
46
- supportsTemplateMode: _supportsTemplateMode,
47
- defaultTemplate: getEditorSettings().defaultBlockTemplate,
48
- };
49
- },
50
- []
51
- );
52
- const { __unstableCreateTemplate, __unstableSwitchToTemplateMode } =
53
- useDispatch( editPostStore );
54
-
55
- if ( ! supportsTemplateMode ) {
56
- return null;
57
- }
58
-
59
- const defaultTitle = __( 'Custom Template' );
60
-
61
- async function onCreateTemplate( event ) {
62
- event.preventDefault();
63
-
64
- if ( isBusy ) {
65
- return;
66
- }
67
-
68
- setIsBusy( true );
69
-
70
- const newTemplateContent =
71
- defaultTemplate ??
72
- serialize( [
73
- createBlock(
74
- 'core/group',
75
- {
76
- tagName: 'header',
77
- layout: { inherit: true },
78
- },
79
- [
80
- createBlock( 'core/site-title' ),
81
- createBlock( 'core/site-tagline' ),
82
- ]
83
- ),
84
- createBlock( 'core/separator' ),
85
- createBlock(
86
- 'core/group',
87
- {
88
- tagName: 'main',
89
- },
90
- [
91
- createBlock(
92
- 'core/group',
93
- {
94
- layout: { inherit: true },
95
- },
96
- [ createBlock( 'core/post-title' ) ]
97
- ),
98
- createBlock( 'core/post-content', {
99
- layout: { inherit: true },
100
- } ),
101
- ]
102
- ),
103
- ] );
104
-
105
- await __unstableCreateTemplate( {
106
- slug: 'wp-custom-template-' + kebabCase( title || defaultTitle ),
107
- content: newTemplateContent,
108
- title: title || defaultTitle,
109
- } );
110
-
111
- setIsBusy( false );
112
- setIsModalOpen( false );
113
-
114
- __unstableSwitchToTemplateMode( true );
115
- }
116
-
117
- return (
118
- <>
119
- <div className="edit-post-template__actions">
120
- { !! template && (
121
- <Button
122
- variant="link"
123
- onClick={ () => __unstableSwitchToTemplateMode() }
124
- label={ sprintf(
125
- // Translators: 1: The title or the slug of the currently selected template.
126
- __( 'Edit template: %s' ),
127
- template?.title.toLowerCase() ?? template.slug
128
- ) }
129
- >
130
- { __( 'Edit' ) }
131
- </Button>
132
- ) }
133
- { ! isPostsPage && (
134
- <Button
135
- variant="link"
136
- onClick={ () => setIsModalOpen( true ) }
137
- label={ _x( 'New template', 'action' ) }
138
- >
139
- {
140
- /* translators: button to create a new template */
141
- _x( 'New', 'action' )
142
- }
143
- </Button>
144
- ) }
145
- </div>
146
- { isModalOpen && (
147
- <Modal
148
- title={ __( 'Create custom template' ) }
149
- closeLabel={ __( 'Close' ) }
150
- onRequestClose={ () => {
151
- setIsModalOpen( false );
152
- setTitle( '' );
153
- } }
154
- overlayClassName="edit-post-template__modal"
155
- >
156
- <form onSubmit={ onCreateTemplate }>
157
- <Flex align="flex-start" gap={ 8 }>
158
- <FlexItem>
159
- <TextControl
160
- label={ __( 'Name' ) }
161
- value={ title }
162
- onChange={ setTitle }
163
- placeholder={ defaultTitle }
164
- disabled={ isBusy }
165
- help={ __(
166
- 'Describe the purpose of the template, e.g. "Full Width". Custom templates can be applied to any post or page.'
167
- ) }
168
- />
169
- </FlexItem>
170
- </Flex>
171
-
172
- <Flex
173
- className="edit-post-template__modal-actions"
174
- justify="flex-end"
175
- expanded={ false }
176
- >
177
- <FlexItem>
178
- <Button
179
- variant="tertiary"
180
- onClick={ () => {
181
- setIsModalOpen( false );
182
- setTitle( '' );
183
- } }
184
- >
185
- { __( 'Cancel' ) }
186
- </Button>
187
- </FlexItem>
188
- <FlexItem>
189
- <Button
190
- variant="primary"
191
- type="submit"
192
- isBusy={ isBusy }
193
- aria-disabled={ isBusy }
194
- >
195
- { __( 'Create' ) }
196
- </Button>
197
- </FlexItem>
198
- </Flex>
199
- </form>
200
- </Modal>
201
- ) }
202
- </>
203
- );
204
- }
205
-
206
- export default PostTemplateActions;