@wordpress/edit-post 6.6.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 (178) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +1 -1
  3. package/build/components/block-manager/category.js.map +1 -1
  4. package/build/components/block-manager/index.js +12 -4
  5. package/build/components/block-manager/index.js.map +1 -1
  6. package/build/components/device-preview/index.js.map +1 -1
  7. package/build/components/editor-initialization/listener-hooks.js.map +1 -1
  8. package/build/components/header/fullscreen-mode-close/index.js.map +1 -1
  9. package/build/components/header/header-toolbar/index.js.map +1 -1
  10. package/build/components/header/index.js.map +1 -1
  11. package/build/components/header/mode-switcher/index.js.map +1 -1
  12. package/build/components/header/post-publish-button-or-toggle.js.map +1 -1
  13. package/build/components/header/template-title/delete-template.js.map +1 -1
  14. package/build/components/header/template-title/index.js.map +1 -1
  15. package/build/components/header/tools-more-menu-group/index.js.map +1 -1
  16. package/build/components/keyboard-shortcut-help-modal/config.js +12 -0
  17. package/build/components/keyboard-shortcut-help-modal/config.js.map +1 -1
  18. package/build/components/keyboard-shortcuts/index.js.map +1 -1
  19. package/build/components/layout/actions-panel.js.map +1 -1
  20. package/build/components/layout/index.js.map +1 -1
  21. package/build/components/layout/index.native.js.map +1 -1
  22. package/build/components/preferences-modal/options/enable-custom-fields.js.map +1 -1
  23. package/build/components/preferences-modal/options/enable-panel.js.map +1 -1
  24. package/build/components/preferences-modal/options/enable-publish-sidebar.js.map +1 -1
  25. package/build/components/secondary-sidebar/inserter-sidebar.js.map +1 -1
  26. package/build/components/sidebar/discussion-panel/index.js.map +1 -1
  27. package/build/components/sidebar/featured-image/index.js.map +1 -1
  28. package/build/components/sidebar/page-attributes/index.js.map +1 -1
  29. package/build/components/sidebar/plugin-document-setting-panel/index.js.map +1 -1
  30. package/build/components/sidebar/plugin-post-status-info/index.js +2 -2
  31. package/build/components/sidebar/plugin-post-status-info/index.js.map +1 -1
  32. package/build/components/sidebar/plugin-sidebar/index.js.map +1 -1
  33. package/build/components/sidebar/post-excerpt/index.js.map +1 -1
  34. package/build/components/sidebar/post-link/index.js.map +1 -1
  35. package/build/components/sidebar/post-schedule/index.js +14 -7
  36. package/build/components/sidebar/post-schedule/index.js.map +1 -1
  37. package/build/components/sidebar/post-status/index.js +4 -2
  38. package/build/components/sidebar/post-status/index.js.map +1 -1
  39. package/build/components/sidebar/post-template/create-modal.js +116 -0
  40. package/build/components/sidebar/post-template/create-modal.js.map +1 -0
  41. package/build/components/sidebar/post-template/form.js +123 -0
  42. package/build/components/sidebar/post-template/form.js.map +1 -0
  43. package/build/components/sidebar/post-template/index.js +123 -0
  44. package/build/components/sidebar/post-template/index.js.map +1 -0
  45. package/build/components/sidebar/settings-sidebar/index.js +1 -3
  46. package/build/components/sidebar/settings-sidebar/index.js.map +1 -1
  47. package/build/components/start-page-options/index.js +31 -13
  48. package/build/components/start-page-options/index.js.map +1 -1
  49. package/build/components/visual-editor/block-inspector-button.js +3 -7
  50. package/build/components/visual-editor/block-inspector-button.js.map +1 -1
  51. package/build/editor.js +1 -1
  52. package/build/editor.js.map +1 -1
  53. package/build/editor.native.js +9 -1
  54. package/build/editor.native.js.map +1 -1
  55. package/build/plugins/copy-content-menu-item/index.js +1 -1
  56. package/build/plugins/copy-content-menu-item/index.js.map +1 -1
  57. package/build/store/actions.js.map +1 -1
  58. package/build/store/selectors.js +8 -8
  59. package/build/store/selectors.js.map +1 -1
  60. package/build-module/components/block-manager/category.js.map +1 -1
  61. package/build-module/components/block-manager/index.js +13 -5
  62. package/build-module/components/block-manager/index.js.map +1 -1
  63. package/build-module/components/device-preview/index.js.map +1 -1
  64. package/build-module/components/editor-initialization/listener-hooks.js.map +1 -1
  65. package/build-module/components/header/fullscreen-mode-close/index.js.map +1 -1
  66. package/build-module/components/header/header-toolbar/index.js.map +1 -1
  67. package/build-module/components/header/index.js.map +1 -1
  68. package/build-module/components/header/mode-switcher/index.js.map +1 -1
  69. package/build-module/components/header/post-publish-button-or-toggle.js.map +1 -1
  70. package/build-module/components/header/template-title/delete-template.js.map +1 -1
  71. package/build-module/components/header/template-title/index.js.map +1 -1
  72. package/build-module/components/header/tools-more-menu-group/index.js.map +1 -1
  73. package/build-module/components/keyboard-shortcut-help-modal/config.js +12 -0
  74. package/build-module/components/keyboard-shortcut-help-modal/config.js.map +1 -1
  75. package/build-module/components/keyboard-shortcuts/index.js.map +1 -1
  76. package/build-module/components/layout/actions-panel.js.map +1 -1
  77. package/build-module/components/layout/index.js.map +1 -1
  78. package/build-module/components/layout/index.native.js.map +1 -1
  79. package/build-module/components/preferences-modal/options/enable-custom-fields.js.map +1 -1
  80. package/build-module/components/preferences-modal/options/enable-panel.js.map +1 -1
  81. package/build-module/components/preferences-modal/options/enable-publish-sidebar.js.map +1 -1
  82. package/build-module/components/secondary-sidebar/inserter-sidebar.js.map +1 -1
  83. package/build-module/components/sidebar/discussion-panel/index.js.map +1 -1
  84. package/build-module/components/sidebar/featured-image/index.js.map +1 -1
  85. package/build-module/components/sidebar/page-attributes/index.js.map +1 -1
  86. package/build-module/components/sidebar/plugin-document-setting-panel/index.js.map +1 -1
  87. package/build-module/components/sidebar/plugin-post-status-info/index.js +2 -2
  88. package/build-module/components/sidebar/plugin-post-status-info/index.js.map +1 -1
  89. package/build-module/components/sidebar/plugin-sidebar/index.js.map +1 -1
  90. package/build-module/components/sidebar/post-excerpt/index.js.map +1 -1
  91. package/build-module/components/sidebar/post-link/index.js.map +1 -1
  92. package/build-module/components/sidebar/post-schedule/index.js +15 -5
  93. package/build-module/components/sidebar/post-schedule/index.js.map +1 -1
  94. package/build-module/components/sidebar/post-status/index.js +3 -2
  95. package/build-module/components/sidebar/post-status/index.js.map +1 -1
  96. package/build-module/components/sidebar/post-template/create-modal.js +104 -0
  97. package/build-module/components/sidebar/post-template/create-modal.js.map +1 -0
  98. package/build-module/components/sidebar/post-template/form.js +106 -0
  99. package/build-module/components/sidebar/post-template/form.js.map +1 -0
  100. package/build-module/components/sidebar/post-template/index.js +109 -0
  101. package/build-module/components/sidebar/post-template/index.js.map +1 -0
  102. package/build-module/components/sidebar/settings-sidebar/index.js +1 -2
  103. package/build-module/components/sidebar/settings-sidebar/index.js.map +1 -1
  104. package/build-module/components/start-page-options/index.js +32 -14
  105. package/build-module/components/start-page-options/index.js.map +1 -1
  106. package/build-module/components/visual-editor/block-inspector-button.js +3 -5
  107. package/build-module/components/visual-editor/block-inspector-button.js.map +1 -1
  108. package/build-module/editor.js +2 -2
  109. package/build-module/editor.js.map +1 -1
  110. package/build-module/editor.native.js +10 -2
  111. package/build-module/editor.native.js.map +1 -1
  112. package/build-module/plugins/copy-content-menu-item/index.js +1 -1
  113. package/build-module/plugins/copy-content-menu-item/index.js.map +1 -1
  114. package/build-module/store/actions.js.map +1 -1
  115. package/build-module/store/selectors.js +8 -7
  116. package/build-module/store/selectors.js.map +1 -1
  117. package/build-style/style-rtl.css +60 -49
  118. package/build-style/style.css +60 -49
  119. package/package.json +28 -28
  120. package/src/components/block-manager/category.js +2 -2
  121. package/src/components/block-manager/index.js +15 -4
  122. package/src/components/device-preview/index.js +4 -6
  123. package/src/components/editor-initialization/listener-hooks.js +2 -3
  124. package/src/components/header/fullscreen-mode-close/index.js +2 -3
  125. package/src/components/header/header-toolbar/index.js +6 -11
  126. package/src/components/header/index.js +6 -9
  127. package/src/components/header/mode-switcher/index.js +4 -4
  128. package/src/components/header/post-publish-button-or-toggle.js +4 -6
  129. package/src/components/header/template-title/delete-template.js +2 -3
  130. package/src/components/header/template-title/index.js +2 -3
  131. package/src/components/header/tools-more-menu-group/index.js +2 -3
  132. package/src/components/keyboard-shortcut-help-modal/config.js +8 -0
  133. package/src/components/keyboard-shortcut-help-modal/test/__snapshots__/index.js.snap +14 -0
  134. package/src/components/keyboard-shortcut-help-modal/test/index.js +2 -1
  135. package/src/components/keyboard-shortcuts/index.js +4 -8
  136. package/src/components/layout/actions-panel.js +6 -9
  137. package/src/components/layout/index.js +12 -21
  138. package/src/components/layout/index.native.js +4 -5
  139. package/src/components/preferences-modal/options/enable-custom-fields.js +2 -2
  140. package/src/components/preferences-modal/options/enable-panel.js +2 -3
  141. package/src/components/preferences-modal/options/enable-publish-sidebar.js +2 -3
  142. package/src/components/secondary-sidebar/inserter-sidebar.js +2 -3
  143. package/src/components/sidebar/discussion-panel/index.js +2 -3
  144. package/src/components/sidebar/featured-image/index.js +2 -3
  145. package/src/components/sidebar/page-attributes/index.js +2 -3
  146. package/src/components/sidebar/plugin-document-setting-panel/index.js +2 -3
  147. package/src/components/sidebar/plugin-post-status-info/index.js +2 -2
  148. package/src/components/sidebar/plugin-sidebar/index.js +2 -3
  149. package/src/components/sidebar/post-excerpt/index.js +2 -3
  150. package/src/components/sidebar/post-link/index.js +2 -3
  151. package/src/components/sidebar/post-schedule/index.js +8 -4
  152. package/src/components/sidebar/post-schedule/style.scss +19 -6
  153. package/src/components/sidebar/post-status/index.js +5 -4
  154. package/src/components/sidebar/post-template/create-modal.js +146 -0
  155. package/src/components/sidebar/post-template/form.js +140 -0
  156. package/src/components/sidebar/post-template/index.js +101 -0
  157. package/src/components/sidebar/post-template/style.scss +46 -0
  158. package/src/components/sidebar/post-visibility/style.scss +5 -4
  159. package/src/components/sidebar/settings-sidebar/index.js +0 -2
  160. package/src/components/start-page-options/index.js +48 -28
  161. package/src/components/visual-editor/block-inspector-button.js +4 -8
  162. package/src/editor.js +8 -10
  163. package/src/editor.native.js +13 -6
  164. package/src/plugins/copy-content-menu-item/index.js +1 -1
  165. package/src/store/actions.js +322 -295
  166. package/src/store/selectors.js +21 -24
  167. package/src/style.scss +1 -1
  168. package/build/components/sidebar/template/actions.js +0 -167
  169. package/build/components/sidebar/template/actions.js.map +0 -1
  170. package/build/components/sidebar/template/index.js +0 -164
  171. package/build/components/sidebar/template/index.js.map +0 -1
  172. package/build-module/components/sidebar/template/actions.js +0 -153
  173. package/build-module/components/sidebar/template/actions.js.map +0 -1
  174. package/build-module/components/sidebar/template/index.js +0 -145
  175. package/build-module/components/sidebar/template/index.js.map +0 -1
  176. package/src/components/sidebar/template/actions.js +0 -203
  177. package/src/components/sidebar/template/index.js +0 -164
  178. package/src/components/sidebar/template/style.scss +0 -43
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = PostTemplateCreateModal;
7
+
8
+ var _element = require("@wordpress/element");
9
+
10
+ var _data = require("@wordpress/data");
11
+
12
+ var _editor = require("@wordpress/editor");
13
+
14
+ var _blocks = require("@wordpress/blocks");
15
+
16
+ var _components = require("@wordpress/components");
17
+
18
+ var _i18n = require("@wordpress/i18n");
19
+
20
+ var _url = require("@wordpress/url");
21
+
22
+ var _store = require("../../../store");
23
+
24
+ /**
25
+ * WordPress dependencies
26
+ */
27
+
28
+ /**
29
+ * Internal dependencies
30
+ */
31
+ const DEFAULT_TITLE = (0, _i18n.__)('Custom Template');
32
+
33
+ function PostTemplateCreateModal(_ref) {
34
+ let {
35
+ onClose
36
+ } = _ref;
37
+ const defaultBlockTemplate = (0, _data.useSelect)(select => select(_editor.store).getEditorSettings().defaultBlockTemplate, []);
38
+ const {
39
+ __unstableCreateTemplate,
40
+ __unstableSwitchToTemplateMode
41
+ } = (0, _data.useDispatch)(_store.store);
42
+ const [title, setTitle] = (0, _element.useState)('');
43
+ const [isBusy, setIsBusy] = (0, _element.useState)(false);
44
+
45
+ const cancel = () => {
46
+ setTitle('');
47
+ onClose();
48
+ };
49
+
50
+ const submit = async event => {
51
+ event.preventDefault();
52
+
53
+ if (isBusy) {
54
+ return;
55
+ }
56
+
57
+ setIsBusy(true);
58
+ const newTemplateContent = defaultBlockTemplate !== null && defaultBlockTemplate !== void 0 ? defaultBlockTemplate : (0, _blocks.serialize)([(0, _blocks.createBlock)('core/group', {
59
+ tagName: 'header',
60
+ layout: {
61
+ inherit: true
62
+ }
63
+ }, [(0, _blocks.createBlock)('core/site-title'), (0, _blocks.createBlock)('core/site-tagline')]), (0, _blocks.createBlock)('core/separator'), (0, _blocks.createBlock)('core/group', {
64
+ tagName: 'main'
65
+ }, [(0, _blocks.createBlock)('core/group', {
66
+ layout: {
67
+ inherit: true
68
+ }
69
+ }, [(0, _blocks.createBlock)('core/post-title')]), (0, _blocks.createBlock)('core/post-content', {
70
+ layout: {
71
+ inherit: true
72
+ }
73
+ })])]);
74
+ await __unstableCreateTemplate({
75
+ slug: (0, _url.cleanForSlug)(title || DEFAULT_TITLE),
76
+ content: newTemplateContent,
77
+ title: title || DEFAULT_TITLE
78
+ });
79
+ setIsBusy(false);
80
+ cancel();
81
+
82
+ __unstableSwitchToTemplateMode(true);
83
+ };
84
+
85
+ return (0, _element.createElement)(_components.Modal, {
86
+ title: (0, _i18n.__)('Create custom template'),
87
+ closeLabel: (0, _i18n.__)('Close'),
88
+ onRequestClose: cancel,
89
+ className: "edit-post-post-template__create-modal"
90
+ }, (0, _element.createElement)("form", {
91
+ className: "edit-post-post-template__create-form",
92
+ onSubmit: submit
93
+ }, (0, _element.createElement)(_components.Flex, {
94
+ align: "flex-start",
95
+ gap: 8
96
+ }, (0, _element.createElement)(_components.FlexItem, null, (0, _element.createElement)(_components.TextControl, {
97
+ label: (0, _i18n.__)('Name'),
98
+ value: title,
99
+ onChange: setTitle,
100
+ placeholder: DEFAULT_TITLE,
101
+ disabled: isBusy,
102
+ help: (0, _i18n.__)('Describe the purpose of the template, e.g. "Full Width". Custom templates can be applied to any post or page.')
103
+ }))), (0, _element.createElement)(_components.Flex, {
104
+ justify: "flex-end",
105
+ expanded: false
106
+ }, (0, _element.createElement)(_components.FlexItem, null, (0, _element.createElement)(_components.Button, {
107
+ variant: "tertiary",
108
+ onClick: cancel
109
+ }, (0, _i18n.__)('Cancel'))), (0, _element.createElement)(_components.FlexItem, null, (0, _element.createElement)(_components.Button, {
110
+ variant: "primary",
111
+ type: "submit",
112
+ isBusy: isBusy,
113
+ "aria-disabled": isBusy
114
+ }, (0, _i18n.__)('Create'))))));
115
+ }
116
+ //# sourceMappingURL=create-modal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/edit-post/src/components/sidebar/post-template/create-modal.js"],"names":["DEFAULT_TITLE","PostTemplateCreateModal","onClose","defaultBlockTemplate","select","editorStore","getEditorSettings","__unstableCreateTemplate","__unstableSwitchToTemplateMode","editPostStore","title","setTitle","isBusy","setIsBusy","cancel","submit","event","preventDefault","newTemplateContent","tagName","layout","inherit","slug","content"],"mappings":";;;;;;;AAKA;;AAFA;;AACA;;AAEA;;AACA;;AAOA;;AACA;;AAKA;;AApBA;AACA;AACA;;AAeA;AACA;AACA;AAGA,MAAMA,aAAa,GAAG,cAAI,iBAAJ,CAAtB;;AAEe,SAASC,uBAAT,OAAgD;AAAA,MAAd;AAAEC,IAAAA;AAAF,GAAc;AAC9D,QAAMC,oBAAoB,GAAG,qBAC1BC,MAAF,IACCA,MAAM,CAAEC,aAAF,CAAN,CAAsBC,iBAAtB,GAA0CH,oBAFf,EAG5B,EAH4B,CAA7B;AAMA,QAAM;AAAEI,IAAAA,wBAAF;AAA4BC,IAAAA;AAA5B,MACL,uBAAaC,YAAb,CADD;AAGA,QAAM,CAAEC,KAAF,EAASC,QAAT,IAAsB,uBAAU,EAAV,CAA5B;AAEA,QAAM,CAAEC,MAAF,EAAUC,SAAV,IAAwB,uBAAU,KAAV,CAA9B;;AAEA,QAAMC,MAAM,GAAG,MAAM;AACpBH,IAAAA,QAAQ,CAAE,EAAF,CAAR;AACAT,IAAAA,OAAO;AACP,GAHD;;AAKA,QAAMa,MAAM,GAAG,MAAQC,KAAR,IAAmB;AACjCA,IAAAA,KAAK,CAACC,cAAN;;AAEA,QAAKL,MAAL,EAAc;AACb;AACA;;AAEDC,IAAAA,SAAS,CAAE,IAAF,CAAT;AAEA,UAAMK,kBAAkB,GACvBf,oBADuB,aACvBA,oBADuB,cACvBA,oBADuB,GAEvB,uBAAW,CACV,yBACC,YADD,EAEC;AACCgB,MAAAA,OAAO,EAAE,QADV;AAECC,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AAA,QAAQ,EAAGC,QAHZ;AAIC,IAAA,WAAW,EAAGX,aAJf;AAKC,IAAA,QAAQ,EAAGY,MALZ;AAMC,IAAA,IAAI,EAAG,cACN,+GADM;AANR,IADD,CADD,CAJD,EAmBC,4BAAC,gBAAD;AAAM,IAAA,OAAO,EAAC,UAAd;AAAyB,IAAA,QAAQ,EAAG;AAApC,KACC,4BAAC,oBAAD,QACC,4BAAC,kBAAD;AAAQ,IAAA,OAAO,EAAC,UAAhB;AAA2B,IAAA,OAAO,EAAGE;AAArC,KACG,cAAI,QAAJ,CADH,CADD,CADD,EAMC,4BAAC,oBAAD,QACC,4BAAC,kBAAD;AACC,IAAA,OAAO,EAAC,SADT;AAEC,IAAA,IAAI,EAAC,QAFN;AAGC,IAAA,MAAM,EAAGF,MAHV;AAIC,qBAAgBA;AAJjB,KAMG,cAAI,QAAJ,CANH,CADD,CAND,CAnBD,CAND,CADD;AA8CA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as editorStore } from '@wordpress/editor';\nimport { useState } from '@wordpress/element';\nimport { serialize, createBlock } from '@wordpress/blocks';\nimport {\n\tModal,\n\tFlex,\n\tFlexItem,\n\tTextControl,\n\tButton,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { cleanForSlug } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { store as editPostStore } from '../../../store';\n\nconst DEFAULT_TITLE = __( 'Custom Template' );\n\nexport default function PostTemplateCreateModal( { onClose } ) {\n\tconst defaultBlockTemplate = useSelect(\n\t\t( select ) =>\n\t\t\tselect( editorStore ).getEditorSettings().defaultBlockTemplate,\n\t\t[]\n\t);\n\n\tconst { __unstableCreateTemplate, __unstableSwitchToTemplateMode } =\n\t\tuseDispatch( editPostStore );\n\n\tconst [ title, setTitle ] = useState( '' );\n\n\tconst [ isBusy, setIsBusy ] = useState( false );\n\n\tconst cancel = () => {\n\t\tsetTitle( '' );\n\t\tonClose();\n\t};\n\n\tconst submit = async ( 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\tdefaultBlockTemplate ??\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: cleanForSlug( title || DEFAULT_TITLE ),\n\t\t\tcontent: newTemplateContent,\n\t\t\ttitle: title || DEFAULT_TITLE,\n\t\t} );\n\n\t\tsetIsBusy( false );\n\t\tcancel();\n\n\t\t__unstableSwitchToTemplateMode( true );\n\t};\n\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ __( 'Create custom template' ) }\n\t\t\tcloseLabel={ __( 'Close' ) }\n\t\t\tonRequestClose={ cancel }\n\t\t\tclassName=\"edit-post-post-template__create-modal\"\n\t\t>\n\t\t\t<form\n\t\t\t\tclassName=\"edit-post-post-template__create-form\"\n\t\t\t\tonSubmit={ submit }\n\t\t\t>\n\t\t\t\t<Flex align=\"flex-start\" gap={ 8 }>\n\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\t\tplaceholder={ DEFAULT_TITLE }\n\t\t\t\t\t\t\tdisabled={ isBusy }\n\t\t\t\t\t\t\thelp={ __(\n\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) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</FlexItem>\n\t\t\t\t</Flex>\n\n\t\t\t\t<Flex justify=\"flex-end\" expanded={ false }>\n\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t<Button variant=\"tertiary\" onClick={ cancel }>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</FlexItem>\n\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\tisBusy={ isBusy }\n\t\t\t\t\t\t\taria-disabled={ isBusy }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Create' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</FlexItem>\n\t\t\t\t</Flex>\n\t\t\t</form>\n\t\t</Modal>\n\t);\n}\n"]}
@@ -0,0 +1,123 @@
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 = PostTemplateForm;
9
+
10
+ var _element = require("@wordpress/element");
11
+
12
+ var _blockEditor = require("@wordpress/block-editor");
13
+
14
+ var _i18n = require("@wordpress/i18n");
15
+
16
+ var _icons = require("@wordpress/icons");
17
+
18
+ var _components = require("@wordpress/components");
19
+
20
+ var _data = require("@wordpress/data");
21
+
22
+ var _editor = require("@wordpress/editor");
23
+
24
+ var _coreData = require("@wordpress/core-data");
25
+
26
+ var _store = require("../../../store");
27
+
28
+ var _createModal = _interopRequireDefault(require("./create-modal"));
29
+
30
+ /**
31
+ * WordPress dependencies
32
+ */
33
+
34
+ /**
35
+ * Internal dependencies
36
+ */
37
+ function PostTemplateForm(_ref) {
38
+ var _options$find, _selectedOption$value;
39
+
40
+ let {
41
+ onClose
42
+ } = _ref;
43
+ const {
44
+ isPostsPage,
45
+ availableTemplates,
46
+ fetchedTemplates,
47
+ selectedTemplateSlug,
48
+ canCreate,
49
+ canEdit
50
+ } = (0, _data.useSelect)(select => {
51
+ const editorSettings = select(_editor.store).getEditorSettings();
52
+ const siteSettings = select(_coreData.store).getEntityRecord('root', 'site');
53
+
54
+ const _isPostsPage = select(_editor.store).getCurrentPostId() === (siteSettings === null || siteSettings === void 0 ? void 0 : siteSettings.page_for_posts);
55
+
56
+ const canCreateTemplates = select(_coreData.store).canUser('create', 'templates');
57
+ return {
58
+ isPostsPage: _isPostsPage,
59
+ availableTemplates: editorSettings.availableTemplates,
60
+ fetchedTemplates: select(_coreData.store).getEntityRecords('postType', 'wp_template', {
61
+ post_type: select(_editor.store).getCurrentPostType(),
62
+ per_page: -1
63
+ }),
64
+ selectedTemplateSlug: select(_editor.store).getEditedPostAttribute('template'),
65
+ canCreate: canCreateTemplates && !_isPostsPage,
66
+ canEdit: canCreateTemplates && editorSettings.supportsTemplateMode && !!select(_store.store).getEditedPostTemplate()
67
+ };
68
+ }, []);
69
+ const options = (0, _element.useMemo)(() => Object.entries({ ...availableTemplates,
70
+ ...Object.fromEntries((fetchedTemplates !== null && fetchedTemplates !== void 0 ? fetchedTemplates : []).map(_ref2 => {
71
+ let {
72
+ slug,
73
+ title
74
+ } = _ref2;
75
+ return [slug, title.rendered];
76
+ }))
77
+ }).map(_ref3 => {
78
+ let [slug, title] = _ref3;
79
+ return {
80
+ value: slug,
81
+ label: title
82
+ };
83
+ }), [availableTemplates, fetchedTemplates]);
84
+ const selectedOption = (_options$find = options.find(option => option.value === selectedTemplateSlug)) !== null && _options$find !== void 0 ? _options$find : options.find(option => !option.value); // The default option has '' value.
85
+
86
+ const {
87
+ editPost
88
+ } = (0, _data.useDispatch)(_editor.store);
89
+ const {
90
+ __unstableSwitchToTemplateMode
91
+ } = (0, _data.useDispatch)(_store.store);
92
+ const [isCreateModalOpen, setIsCreateModalOpen] = (0, _element.useState)(false);
93
+ return (0, _element.createElement)("div", {
94
+ className: "edit-post-post-template__form"
95
+ }, (0, _element.createElement)(_blockEditor.__experimentalInspectorPopoverHeader, {
96
+ title: (0, _i18n.__)('Template'),
97
+ help: (0, _i18n.__)('Templates define the way content is displayed when viewing your site.'),
98
+ actions: canCreate ? [{
99
+ icon: _icons.addTemplate,
100
+ label: (0, _i18n.__)('Add template'),
101
+ onClick: () => setIsCreateModalOpen(true)
102
+ }] : [],
103
+ onClose: onClose
104
+ }), isPostsPage ? (0, _element.createElement)(_components.Notice, {
105
+ className: "edit-post-post-template__notice",
106
+ status: "warning",
107
+ isDismissible: false
108
+ }, (0, _i18n.__)('The posts page template cannot be changed.')) : (0, _element.createElement)(_components.SelectControl, {
109
+ hideLabelFromVision: true,
110
+ label: (0, _i18n.__)('Template'),
111
+ value: (_selectedOption$value = selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.value) !== null && _selectedOption$value !== void 0 ? _selectedOption$value : '',
112
+ options: options,
113
+ onChange: slug => editPost({
114
+ template: slug || ''
115
+ })
116
+ }), canEdit && (0, _element.createElement)("p", null, (0, _element.createElement)(_components.Button, {
117
+ variant: "link",
118
+ onClick: () => __unstableSwitchToTemplateMode()
119
+ }, (0, _i18n.__)('Edit template'))), isCreateModalOpen && (0, _element.createElement)(_createModal.default, {
120
+ onClose: () => setIsCreateModalOpen(false)
121
+ }));
122
+ }
123
+ //# sourceMappingURL=form.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/edit-post/src/components/sidebar/post-template/form.js"],"names":["PostTemplateForm","onClose","isPostsPage","availableTemplates","fetchedTemplates","selectedTemplateSlug","canCreate","canEdit","select","editorSettings","editorStore","getEditorSettings","siteSettings","coreStore","getEntityRecord","_isPostsPage","getCurrentPostId","page_for_posts","canCreateTemplates","canUser","getEntityRecords","post_type","getCurrentPostType","per_page","getEditedPostAttribute","supportsTemplateMode","editPostStore","getEditedPostTemplate","options","Object","entries","fromEntries","map","slug","title","rendered","value","label","selectedOption","find","option","editPost","__unstableSwitchToTemplateMode","isCreateModalOpen","setIsCreateModalOpen","icon","addTemplate","onClick","template"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAhBA;AACA;AACA;;AAUA;AACA;AACA;AAIe,SAASA,gBAAT,OAAyC;AAAA;;AAAA,MAAd;AAAEC,IAAAA;AAAF,GAAc;AACvD,QAAM;AACLC,IAAAA,WADK;AAELC,IAAAA,kBAFK;AAGLC,IAAAA,gBAHK;AAILC,IAAAA,oBAJK;AAKLC,IAAAA,SALK;AAMLC,IAAAA;AANK,MAOF,qBAAaC,MAAF,IAAc;AAC5B,UAAMC,cAAc,GAAGD,MAAM,CAAEE,aAAF,CAAN,CAAsBC,iBAAtB,EAAvB;AACA,UAAMC,YAAY,GAAGJ,MAAM,CAAEK,eAAF,CAAN,CAAoBC,eAApB,CACpB,MADoB,EAEpB,MAFoB,CAArB;;AAIA,UAAMC,YAAY,GACjBP,MAAM,CAAEE,aAAF,CAAN,CAAsBM,gBAAtB,QACAJ,YADA,aACAA,YADA,uBACAA,YAAY,CAAEK,cADd,CADD;;AAGA,UAAMC,kBAAkB,GAAGV,MAAM,CAAEK,eAAF,CAAN,CAAoBM,OAAp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AQ,CAAE;AAAEO,MAAAA,QAAQ,EAAEf,IAAI,IAAI;AAApB,KAAF;AANV,IA5BF,EAsCG1B,OAAO,IACR,uCACC,4BAAC,kBAAD;AACC,IAAA,OAAO,EAAC,MADT;AAEC,IAAA,OAAO,EAAG,MAAMmC,8BAA8B;AAF/C,KAIG,cAAI,eAAJ,CAJH,CADD,CAvCF,EAgDGC,iBAAiB,IAClB,4BAAC,oBAAD;AACC,IAAA,OAAO,EAAG,MAAMC,oBAAoB,CAAE,KAAF;AADrC,IAjDF,CADD;AAwDA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useMemo } from '@wordpress/element';\nimport { __experimentalInspectorPopoverHeader as InspectorPopoverHeader } from '@wordpress/block-editor';\nimport { __ } from '@wordpress/i18n';\nimport { addTemplate } from '@wordpress/icons';\nimport { Notice, SelectControl, Button } from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\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 PostTemplateCreateModal from './create-modal';\n\nexport default function PostTemplateForm( { onClose } ) {\n\tconst {\n\t\tisPostsPage,\n\t\tavailableTemplates,\n\t\tfetchedTemplates,\n\t\tselectedTemplateSlug,\n\t\tcanCreate,\n\t\tcanEdit,\n\t} = useSelect( ( select ) => {\n\t\tconst editorSettings = select( editorStore ).getEditorSettings();\n\t\tconst siteSettings = select( coreStore ).getEntityRecord(\n\t\t\t'root',\n\t\t\t'site'\n\t\t);\n\t\tconst _isPostsPage =\n\t\t\tselect( editorStore ).getCurrentPostId() ===\n\t\t\tsiteSettings?.page_for_posts;\n\t\tconst canCreateTemplates = select( coreStore ).canUser(\n\t\t\t'create',\n\t\t\t'templates'\n\t\t);\n\t\treturn {\n\t\t\tisPostsPage: _isPostsPage,\n\t\t\tavailableTemplates: editorSettings.availableTemplates,\n\t\t\tfetchedTemplates: select( coreStore ).getEntityRecords(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template',\n\t\t\t\t{\n\t\t\t\t\tpost_type: select( editorStore ).getCurrentPostType(),\n\t\t\t\t\tper_page: -1,\n\t\t\t\t}\n\t\t\t),\n\t\t\tselectedTemplateSlug:\n\t\t\t\tselect( editorStore ).getEditedPostAttribute( 'template' ),\n\t\t\tcanCreate: canCreateTemplates && ! _isPostsPage,\n\t\t\tcanEdit:\n\t\t\t\tcanCreateTemplates &&\n\t\t\t\teditorSettings.supportsTemplateMode &&\n\t\t\t\t!! select( editPostStore ).getEditedPostTemplate(),\n\t\t};\n\t}, [] );\n\n\tconst options = useMemo(\n\t\t() =>\n\t\t\tObject.entries( {\n\t\t\t\t...availableTemplates,\n\t\t\t\t...Object.fromEntries(\n\t\t\t\t\t( fetchedTemplates ?? [] ).map( ( { slug, title } ) => [\n\t\t\t\t\t\tslug,\n\t\t\t\t\t\ttitle.rendered,\n\t\t\t\t\t] )\n\t\t\t\t),\n\t\t\t} ).map( ( [ slug, title ] ) => ( { value: slug, label: title } ) ),\n\t\t[ availableTemplates, fetchedTemplates ]\n\t);\n\n\tconst selectedOption =\n\t\toptions.find( ( option ) => option.value === selectedTemplateSlug ) ??\n\t\toptions.find( ( option ) => ! option.value ); // The default option has '' value.\n\n\tconst { editPost } = useDispatch( editorStore );\n\tconst { __unstableSwitchToTemplateMode } = useDispatch( editPostStore );\n\n\tconst [ isCreateModalOpen, setIsCreateModalOpen ] = useState( false );\n\n\treturn (\n\t\t<div className=\"edit-post-post-template__form\">\n\t\t\t<InspectorPopoverHeader\n\t\t\t\ttitle={ __( 'Template' ) }\n\t\t\t\thelp={ __(\n\t\t\t\t\t'Templates define the way content is displayed when viewing your site.'\n\t\t\t\t) }\n\t\t\t\tactions={\n\t\t\t\t\tcanCreate\n\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\ticon: addTemplate,\n\t\t\t\t\t\t\t\t\tlabel: __( 'Add template' ),\n\t\t\t\t\t\t\t\t\tonClick: () => setIsCreateModalOpen( true ),\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t ]\n\t\t\t\t\t\t: []\n\t\t\t\t}\n\t\t\t\tonClose={ onClose }\n\t\t\t/>\n\t\t\t{ isPostsPage ? (\n\t\t\t\t<Notice\n\t\t\t\t\tclassName=\"edit-post-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={ selectedOption?.value ?? '' }\n\t\t\t\t\toptions={ options }\n\t\t\t\t\tonChange={ ( slug ) =>\n\t\t\t\t\t\teditPost( { template: slug || '' } )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ canEdit && (\n\t\t\t\t<p>\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>\n\t\t\t\t\t\t{ __( 'Edit template' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</p>\n\t\t\t) }\n\t\t\t{ isCreateModalOpen && (\n\t\t\t\t<PostTemplateCreateModal\n\t\t\t\t\tonClose={ () => setIsCreateModalOpen( false ) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</div>\n\t);\n}\n"]}
@@ -0,0 +1,123 @@
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 = PostTemplate;
9
+
10
+ var _element = require("@wordpress/element");
11
+
12
+ var _components = require("@wordpress/components");
13
+
14
+ var _i18n = require("@wordpress/i18n");
15
+
16
+ var _data = require("@wordpress/data");
17
+
18
+ var _editor = require("@wordpress/editor");
19
+
20
+ var _coreData = require("@wordpress/core-data");
21
+
22
+ var _form = _interopRequireDefault(require("./form"));
23
+
24
+ /**
25
+ * WordPress dependencies
26
+ */
27
+
28
+ /**
29
+ * Internal dependencies
30
+ */
31
+ function PostTemplate() {
32
+ const anchorRef = (0, _element.useRef)();
33
+ const isVisible = (0, _data.useSelect)(select => {
34
+ var _select$canUser;
35
+
36
+ const postTypeSlug = select(_editor.store).getCurrentPostType();
37
+ const postType = select(_coreData.store).getPostType(postTypeSlug);
38
+
39
+ if (!(postType !== null && postType !== void 0 && postType.viewable)) {
40
+ return false;
41
+ }
42
+
43
+ const settings = select(_editor.store).getEditorSettings();
44
+ const hasTemplates = !!settings.availableTemplates && Object.keys(settings.availableTemplates).length > 0;
45
+
46
+ if (hasTemplates) {
47
+ return true;
48
+ }
49
+
50
+ const canCreateTemplates = (_select$canUser = select(_coreData.store).canUser('create', 'templates')) !== null && _select$canUser !== void 0 ? _select$canUser : false;
51
+ return canCreateTemplates;
52
+ }, []);
53
+
54
+ if (!isVisible) {
55
+ return null;
56
+ }
57
+
58
+ return (0, _element.createElement)(_components.PanelRow, {
59
+ className: "edit-post-post-template",
60
+ ref: anchorRef
61
+ }, (0, _element.createElement)("span", null, (0, _i18n.__)('Template')), (0, _element.createElement)(_components.Dropdown, {
62
+ popoverProps: {
63
+ anchorRef
64
+ },
65
+ position: "bottom left",
66
+ className: "edit-post-post-template__dropdown",
67
+ contentClassName: "edit-post-post-template__dialog",
68
+ renderToggle: _ref => {
69
+ let {
70
+ isOpen,
71
+ onToggle
72
+ } = _ref;
73
+ return (0, _element.createElement)(PostTemplateToggle, {
74
+ isOpen: isOpen,
75
+ onClick: onToggle
76
+ });
77
+ },
78
+ renderContent: _ref2 => {
79
+ let {
80
+ onClose
81
+ } = _ref2;
82
+ return (0, _element.createElement)(_form.default, {
83
+ onClose: onClose
84
+ });
85
+ }
86
+ }));
87
+ }
88
+
89
+ function PostTemplateToggle(_ref3) {
90
+ let {
91
+ isOpen,
92
+ onClick
93
+ } = _ref3;
94
+ const templateTitle = (0, _data.useSelect)(select => {
95
+ var _select$getEntityReco;
96
+
97
+ const templateSlug = select(_editor.store).getEditedPostAttribute('template');
98
+ const settings = select(_editor.store).getEditorSettings();
99
+
100
+ if (settings.availableTemplates[templateSlug]) {
101
+ return settings.availableTemplates[templateSlug];
102
+ }
103
+
104
+ const template = (_select$getEntityReco = select(_coreData.store).getEntityRecords('postType', 'wp_template', {
105
+ per_page: -1
106
+ })) === null || _select$getEntityReco === void 0 ? void 0 : _select$getEntityReco.find(_ref4 => {
107
+ let {
108
+ slug
109
+ } = _ref4;
110
+ return slug === templateSlug;
111
+ });
112
+ return template === null || template === void 0 ? void 0 : template.title.rendered;
113
+ }, []);
114
+ return (0, _element.createElement)(_components.Button, {
115
+ className: "edit-post-post-template__toggle",
116
+ variant: "tertiary",
117
+ "aria-expanded": isOpen,
118
+ "aria-label": templateTitle ? (0, _i18n.sprintf)( // translators: %s: Name of the currently selected template.
119
+ (0, _i18n.__)('Select template: %s'), templateTitle) : (0, _i18n.__)('Select template'),
120
+ onClick: onClick
121
+ }, templateTitle !== null && templateTitle !== void 0 ? templateTitle : (0, _i18n.__)('(none)'));
122
+ }
123
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/edit-post/src/components/sidebar/post-template/index.js"],"names":["PostTemplate","anchorRef","isVisible","select","postTypeSlug","editorStore","getCurrentPostType","postType","coreStore","getPostType","viewable","settings","getEditorSettings","hasTemplates","availableTemplates","Object","keys","length","canCreateTemplates","canUser","isOpen","onToggle","onClose","PostTemplateToggle","onClick","templateTitle","templateSlug","getEditedPostAttribute","template","getEntityRecords","per_page","find","slug","title","rendered"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AAbA;AACA;AACA;;AAQA;AACA;AACA;AAGe,SAASA,YAAT,GAAwB;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J,CAFA,EAGAA,aAHA,CADU,GAMV,cAAI,iBAAJ,CAXL;AAaC,IAAA,OAAO,EAAGD;AAbX,KAeGC,aAfH,aAeGA,aAfH,cAeGA,aAfH,GAeoB,cAAI,QAAJ,CAfpB,CADD;AAmBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef } from '@wordpress/element';\nimport { PanelRow, Dropdown, Button } from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useSelect } from '@wordpress/data';\nimport { store as editorStore } from '@wordpress/editor';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport PostTemplateForm from './form';\n\nexport default function PostTemplate() {\n\tconst anchorRef = useRef();\n\n\tconst isVisible = useSelect( ( select ) => {\n\t\tconst postTypeSlug = select( editorStore ).getCurrentPostType();\n\t\tconst postType = select( coreStore ).getPostType( postTypeSlug );\n\t\tif ( ! postType?.viewable ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst settings = select( editorStore ).getEditorSettings();\n\t\tconst hasTemplates =\n\t\t\t!! settings.availableTemplates &&\n\t\t\tObject.keys( settings.availableTemplates ).length > 0;\n\t\tif ( hasTemplates ) {\n\t\t\treturn true;\n\t\t}\n\n\t\tconst canCreateTemplates =\n\t\t\tselect( coreStore ).canUser( 'create', 'templates' ) ?? false;\n\t\treturn canCreateTemplates;\n\t}, [] );\n\n\tif ( ! isVisible ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<PanelRow className=\"edit-post-post-template\" ref={ anchorRef }>\n\t\t\t<span>{ __( 'Template' ) }</span>\n\t\t\t<Dropdown\n\t\t\t\tpopoverProps={ { anchorRef } }\n\t\t\t\tposition=\"bottom left\"\n\t\t\t\tclassName=\"edit-post-post-template__dropdown\"\n\t\t\t\tcontentClassName=\"edit-post-post-template__dialog\"\n\t\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t\t<PostTemplateToggle\n\t\t\t\t\t\tisOpen={ isOpen }\n\t\t\t\t\t\tonClick={ onToggle }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\trenderContent={ ( { onClose } ) => (\n\t\t\t\t\t<PostTemplateForm onClose={ onClose } />\n\t\t\t\t) }\n\t\t\t/>\n\t\t</PanelRow>\n\t);\n}\n\nfunction PostTemplateToggle( { isOpen, onClick } ) {\n\tconst templateTitle = useSelect( ( select ) => {\n\t\tconst templateSlug =\n\t\t\tselect( editorStore ).getEditedPostAttribute( 'template' );\n\n\t\tconst settings = select( editorStore ).getEditorSettings();\n\t\tif ( settings.availableTemplates[ templateSlug ] ) {\n\t\t\treturn settings.availableTemplates[ templateSlug ];\n\t\t}\n\n\t\tconst template = select( coreStore )\n\t\t\t.getEntityRecords( 'postType', 'wp_template', { per_page: -1 } )\n\t\t\t?.find( ( { slug } ) => slug === templateSlug );\n\n\t\treturn template?.title.rendered;\n\t}, [] );\n\n\treturn (\n\t\t<Button\n\t\t\tclassName=\"edit-post-post-template__toggle\"\n\t\t\tvariant=\"tertiary\"\n\t\t\taria-expanded={ isOpen }\n\t\t\taria-label={\n\t\t\t\ttemplateTitle\n\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t// translators: %s: Name of the currently selected template.\n\t\t\t\t\t\t\t__( 'Select template: %s' ),\n\t\t\t\t\t\t\ttemplateTitle\n\t\t\t\t\t )\n\t\t\t\t\t: __( 'Select template' )\n\t\t\t}\n\t\t\tonClick={ onClick }\n\t\t>\n\t\t\t{ templateTitle ?? __( '(none)' ) }\n\t\t</Button>\n\t);\n}\n"]}
@@ -41,8 +41,6 @@ var _pluginDocumentSettingPanel = _interopRequireDefault(require("../plugin-docu
41
41
 
42
42
  var _pluginSidebar = _interopRequireDefault(require("../plugin-sidebar"));
43
43
 
44
- var _template = _interopRequireDefault(require("../template"));
45
-
46
44
  var _templateSummary = _interopRequireDefault(require("../template-summary"));
47
45
 
48
46
  var _i18n = require("@wordpress/i18n");
@@ -106,7 +104,7 @@ const SettingsSidebar = () => {
106
104
  toggleShortcut: keyboardShortcut,
107
105
  icon: _icons.cog,
108
106
  isActiveByDefault: SIDEBAR_ACTIVE_BY_DEFAULT
109
- }, !isTemplateMode && sidebarName === 'edit-post/document' && (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_postStatus.default, null), (0, _element.createElement)(_template.default, null), (0, _element.createElement)(_pluginDocumentSettingPanel.default.Slot, null), (0, _element.createElement)(_lastRevision.default, null), (0, _element.createElement)(_postLink.default, null), (0, _element.createElement)(_postTaxonomies.default, null), (0, _element.createElement)(_featuredImage.default, null), (0, _element.createElement)(_postExcerpt.default, null), (0, _element.createElement)(_discussionPanel.default, null), (0, _element.createElement)(_pageAttributes.default, null), (0, _element.createElement)(_metaBoxes.default, {
107
+ }, !isTemplateMode && sidebarName === 'edit-post/document' && (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_postStatus.default, null), (0, _element.createElement)(_pluginDocumentSettingPanel.default.Slot, null), (0, _element.createElement)(_lastRevision.default, null), (0, _element.createElement)(_postLink.default, null), (0, _element.createElement)(_postTaxonomies.default, null), (0, _element.createElement)(_featuredImage.default, null), (0, _element.createElement)(_postExcerpt.default, null), (0, _element.createElement)(_discussionPanel.default, null), (0, _element.createElement)(_pageAttributes.default, null), (0, _element.createElement)(_metaBoxes.default, {
110
108
  location: "side"
111
109
  })), isTemplateMode && sidebarName === 'edit-post/document' && (0, _element.createElement)(_templateSummary.default, null), sidebarName === 'edit-post/block' && (0, _element.createElement)(_blockEditor.BlockInspector, null));
112
110
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-post/src/components/sidebar/settings-sidebar/index.js"],"names":["SIDEBAR_ACTIVE_BY_DEFAULT","Platform","select","web","native","SettingsSidebar","sidebarName","keyboardShortcut","isTemplateMode","sidebar","interfaceStore","getActiveComplementaryArea","editPostStore","name","includes","blockEditorStore","getBlockSelectionStart","shortcut","keyboardShortcutsStore","getShortcutRepresentation","isEditingTemplate","cog"],"mappings":";;;;;;;;;AA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AAA,UAAU,EAAG,cAAI,gBAAJ,CAHd;AAIC,IAAA,eAAe,EAAC;AAChB;AALD;AAMC,IAAA,KAAK,EAAG,cAAI,UAAJ,CANT;AAOC,IAAA,cAAc,EAAGC,gBAPlB;AAQC,IAAA,IAAI,EAAGc,UARR;AASC,IAAA,iBAAiB,EAAGrB;AATrB,KAWG,CAAEQ,cAAF,IAAoBF,WAAW,KAAK,oBAApC,IACD,qDACC,4BAAC,mBAAD,OADD,EAEC,4BAAC,iBAAD,OAFD,EAGC,4BAAC,mCAAD,CAA4B,IAA5B,OAHD,EAIC,4BAAC,qBAAD,OAJD,EAKC,4BAAC,iBAAD,OALD,EAMC,4BAAC,uBAAD,OAND,EAOC,4BAAC,sBAAD,OAPD,EAQC,4BAAC,oBAAD,OARD,EASC,4BAAC,wBAAD,OATD,EAUC,4BAAC,uBAAD,OAVD,EAWC,4BAAC,kBAAD;AAAW,IAAA,QAAQ,EAAC;AAApB,IAXD,CAZF,EA0BGE,cAAc,IAAIF,WAAW,KAAK,oBAAlC,IACD,4BAAC,wBAAD,OA3BF,EA6BGA,WAAW,KAAK,iBAAhB,IAAqC,4BAAC,2BAAD,OA7BxC,CADD;AAiCA,CApED;;eAsEeD,e","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tBlockInspector,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { cog } from '@wordpress/icons';\nimport { Platform } from '@wordpress/element';\nimport { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\nimport { store as interfaceStore } from '@wordpress/interface';\n\n/**\n * Internal dependencies\n */\nimport SettingsHeader from '../settings-header';\nimport PostStatus from '../post-status';\nimport LastRevision from '../last-revision';\nimport PostTaxonomies from '../post-taxonomies';\nimport FeaturedImage from '../featured-image';\nimport PostExcerpt from '../post-excerpt';\nimport PostLink from '../post-link';\nimport DiscussionPanel from '../discussion-panel';\nimport PageAttributes from '../page-attributes';\nimport MetaBoxes from '../../meta-boxes';\nimport PluginDocumentSettingPanel from '../plugin-document-setting-panel';\nimport PluginSidebarEditPost from '../plugin-sidebar';\nimport Template from '../template';\nimport TemplateSummary from '../template-summary';\nimport { __ } from '@wordpress/i18n';\nimport { useSelect } from '@wordpress/data';\nimport { store as editPostStore } from '../../../store';\n\nconst SIDEBAR_ACTIVE_BY_DEFAULT = Platform.select( {\n\tweb: true,\n\tnative: false,\n} );\n\nconst SettingsSidebar = () => {\n\tconst { sidebarName, keyboardShortcut, isTemplateMode } = useSelect(\n\t\t( select ) => {\n\t\t\t// The settings sidebar is used by the edit-post/document and edit-post/block sidebars.\n\t\t\t// sidebarName represents the sidebar that is active or that should be active when the SettingsSidebar toggle button is pressed.\n\t\t\t// If one of the two sidebars is active the component will contain the content of that sidebar.\n\t\t\t// When neither of the the two sidebars is active we can not simply return null, because the PluginSidebarEditPost\n\t\t\t// component, besides being used to render the sidebar, also renders the toggle button. In that case sidebarName\n\t\t\t// should contain the sidebar that will be active when the toggle button is pressed. If a block\n\t\t\t// is selected, that should be edit-post/block otherwise it's edit-post/document.\n\t\t\tlet sidebar = select( interfaceStore ).getActiveComplementaryArea(\n\t\t\t\teditPostStore.name\n\t\t\t);\n\t\t\tif (\n\t\t\t\t! [ 'edit-post/document', 'edit-post/block' ].includes(\n\t\t\t\t\tsidebar\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tif ( select( blockEditorStore ).getBlockSelectionStart() ) {\n\t\t\t\t\tsidebar = 'edit-post/block';\n\t\t\t\t}\n\t\t\t\tsidebar = 'edit-post/document';\n\t\t\t}\n\t\t\tconst shortcut = select(\n\t\t\t\tkeyboardShortcutsStore\n\t\t\t).getShortcutRepresentation( 'core/edit-post/toggle-sidebar' );\n\t\t\treturn {\n\t\t\t\tsidebarName: sidebar,\n\t\t\t\tkeyboardShortcut: shortcut,\n\t\t\t\tisTemplateMode: select( editPostStore ).isEditingTemplate(),\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\n\treturn (\n\t\t<PluginSidebarEditPost\n\t\t\tidentifier={ sidebarName }\n\t\t\theader={ <SettingsHeader sidebarName={ sidebarName } /> }\n\t\t\tcloseLabel={ __( 'Close settings' ) }\n\t\t\theaderClassName=\"edit-post-sidebar__panel-tabs\"\n\t\t\t/* translators: button label text should, if possible, be under 16 characters. */\n\t\t\ttitle={ __( 'Settings' ) }\n\t\t\ttoggleShortcut={ keyboardShortcut }\n\t\t\ticon={ cog }\n\t\t\tisActiveByDefault={ SIDEBAR_ACTIVE_BY_DEFAULT }\n\t\t>\n\t\t\t{ ! isTemplateMode && sidebarName === 'edit-post/document' && (\n\t\t\t\t<>\n\t\t\t\t\t<PostStatus />\n\t\t\t\t\t<Template />\n\t\t\t\t\t<PluginDocumentSettingPanel.Slot />\n\t\t\t\t\t<LastRevision />\n\t\t\t\t\t<PostLink />\n\t\t\t\t\t<PostTaxonomies />\n\t\t\t\t\t<FeaturedImage />\n\t\t\t\t\t<PostExcerpt />\n\t\t\t\t\t<DiscussionPanel />\n\t\t\t\t\t<PageAttributes />\n\t\t\t\t\t<MetaBoxes location=\"side\" />\n\t\t\t\t</>\n\t\t\t) }\n\t\t\t{ isTemplateMode && sidebarName === 'edit-post/document' && (\n\t\t\t\t<TemplateSummary />\n\t\t\t) }\n\t\t\t{ sidebarName === 'edit-post/block' && <BlockInspector /> }\n\t\t</PluginSidebarEditPost>\n\t);\n};\n\nexport default SettingsSidebar;\n"]}
1
+ {"version":3,"sources":["@wordpress/edit-post/src/components/sidebar/settings-sidebar/index.js"],"names":["SIDEBAR_ACTIVE_BY_DEFAULT","Platform","select","web","native","SettingsSidebar","sidebarName","keyboardShortcut","isTemplateMode","sidebar","interfaceStore","getActiveComplementaryArea","editPostStore","name","includes","blockEditorStore","getBlockSelectionStart","shortcut","keyboardShortcutsStore","getShortcutRepresentation","isEditingTemplate","cog"],"mappings":";;;;;;;;;AAQA;;AALA;;AAIA;;AAEA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;A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I,UAAJ,CANT;AAOC,IAAA,cAAc,EAAGC,gBAPlB;AAQC,IAAA,IAAI,EAAGc,UARR;AASC,IAAA,iBAAiB,EAAGrB;AATrB,KAWG,CAAEQ,cAAF,IAAoBF,WAAW,KAAK,oBAApC,IACD,qDACC,4BAAC,mBAAD,OADD,EAEC,4BAAC,mCAAD,CAA4B,IAA5B,OAFD,EAGC,4BAAC,qBAAD,OAHD,EAIC,4BAAC,iBAAD,OAJD,EAKC,4BAAC,uBAAD,OALD,EAMC,4BAAC,sBAAD,OAND,EAOC,4BAAC,oBAAD,OAPD,EAQC,4BAAC,wBAAD,OARD,EASC,4BAAC,uBAAD,OATD,EAUC,4BAAC,kBAAD;AAAW,IAAA,QAAQ,EAAC;AAApB,IAVD,CAZF,EAyBGE,cAAc,IAAIF,WAAW,KAAK,oBAAlC,IACD,4BAAC,wBAAD,OA1BF,EA4BGA,WAAW,KAAK,iBAAhB,IAAqC,4BAAC,2BAAD,OA5BxC,CADD;AAgCA,CAnED;;eAqEeD,e","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tBlockInspector,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { cog } from '@wordpress/icons';\nimport { Platform } from '@wordpress/element';\nimport { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\nimport { store as interfaceStore } from '@wordpress/interface';\n\n/**\n * Internal dependencies\n */\nimport SettingsHeader from '../settings-header';\nimport PostStatus from '../post-status';\nimport LastRevision from '../last-revision';\nimport PostTaxonomies from '../post-taxonomies';\nimport FeaturedImage from '../featured-image';\nimport PostExcerpt from '../post-excerpt';\nimport PostLink from '../post-link';\nimport DiscussionPanel from '../discussion-panel';\nimport PageAttributes from '../page-attributes';\nimport MetaBoxes from '../../meta-boxes';\nimport PluginDocumentSettingPanel from '../plugin-document-setting-panel';\nimport PluginSidebarEditPost from '../plugin-sidebar';\nimport TemplateSummary from '../template-summary';\nimport { __ } from '@wordpress/i18n';\nimport { useSelect } from '@wordpress/data';\nimport { store as editPostStore } from '../../../store';\n\nconst SIDEBAR_ACTIVE_BY_DEFAULT = Platform.select( {\n\tweb: true,\n\tnative: false,\n} );\n\nconst SettingsSidebar = () => {\n\tconst { sidebarName, keyboardShortcut, isTemplateMode } = useSelect(\n\t\t( select ) => {\n\t\t\t// The settings sidebar is used by the edit-post/document and edit-post/block sidebars.\n\t\t\t// sidebarName represents the sidebar that is active or that should be active when the SettingsSidebar toggle button is pressed.\n\t\t\t// If one of the two sidebars is active the component will contain the content of that sidebar.\n\t\t\t// When neither of the the two sidebars is active we can not simply return null, because the PluginSidebarEditPost\n\t\t\t// component, besides being used to render the sidebar, also renders the toggle button. In that case sidebarName\n\t\t\t// should contain the sidebar that will be active when the toggle button is pressed. If a block\n\t\t\t// is selected, that should be edit-post/block otherwise it's edit-post/document.\n\t\t\tlet sidebar = select( interfaceStore ).getActiveComplementaryArea(\n\t\t\t\teditPostStore.name\n\t\t\t);\n\t\t\tif (\n\t\t\t\t! [ 'edit-post/document', 'edit-post/block' ].includes(\n\t\t\t\t\tsidebar\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tif ( select( blockEditorStore ).getBlockSelectionStart() ) {\n\t\t\t\t\tsidebar = 'edit-post/block';\n\t\t\t\t}\n\t\t\t\tsidebar = 'edit-post/document';\n\t\t\t}\n\t\t\tconst shortcut = select(\n\t\t\t\tkeyboardShortcutsStore\n\t\t\t).getShortcutRepresentation( 'core/edit-post/toggle-sidebar' );\n\t\t\treturn {\n\t\t\t\tsidebarName: sidebar,\n\t\t\t\tkeyboardShortcut: shortcut,\n\t\t\t\tisTemplateMode: select( editPostStore ).isEditingTemplate(),\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\n\treturn (\n\t\t<PluginSidebarEditPost\n\t\t\tidentifier={ sidebarName }\n\t\t\theader={ <SettingsHeader sidebarName={ sidebarName } /> }\n\t\t\tcloseLabel={ __( 'Close settings' ) }\n\t\t\theaderClassName=\"edit-post-sidebar__panel-tabs\"\n\t\t\t/* translators: button label text should, if possible, be under 16 characters. */\n\t\t\ttitle={ __( 'Settings' ) }\n\t\t\ttoggleShortcut={ keyboardShortcut }\n\t\t\ticon={ cog }\n\t\t\tisActiveByDefault={ SIDEBAR_ACTIVE_BY_DEFAULT }\n\t\t>\n\t\t\t{ ! isTemplateMode && sidebarName === 'edit-post/document' && (\n\t\t\t\t<>\n\t\t\t\t\t<PostStatus />\n\t\t\t\t\t<PluginDocumentSettingPanel.Slot />\n\t\t\t\t\t<LastRevision />\n\t\t\t\t\t<PostLink />\n\t\t\t\t\t<PostTaxonomies />\n\t\t\t\t\t<FeaturedImage />\n\t\t\t\t\t<PostExcerpt />\n\t\t\t\t\t<DiscussionPanel />\n\t\t\t\t\t<PageAttributes />\n\t\t\t\t\t<MetaBoxes location=\"side\" />\n\t\t\t\t</>\n\t\t\t) }\n\t\t\t{ isTemplateMode && sidebarName === 'edit-post/document' && (\n\t\t\t\t<TemplateSummary />\n\t\t\t) }\n\t\t\t{ sidebarName === 'edit-post/block' && <BlockInspector /> }\n\t\t</PluginSidebarEditPost>\n\t);\n};\n\nexport default SettingsSidebar;\n"]}
@@ -28,20 +28,40 @@ var _store = require("../../store");
28
28
  /**
29
29
  * Internal dependencies
30
30
  */
31
- function PatternSelection(_ref) {
32
- let {
33
- onChoosePattern
34
- } = _ref;
31
+ function useStartPatterns() {
32
+ // A pattern is a start pattern if it includes 'core/post-content' in its blockTypes,
33
+ // and it has no postTypes declares and the current post type is page or if
34
+ // the current post type is part of the postTypes declared.
35
35
  const {
36
- blockPatterns
36
+ blockPatternsWithPostContentBlockType,
37
+ postType
37
38
  } = (0, _data.useSelect)(select => {
38
39
  const {
39
40
  __experimentalGetPatternsByBlockTypes
40
41
  } = select(_blockEditor.store);
42
+ const {
43
+ getCurrentPostType
44
+ } = select(_editor.store);
41
45
  return {
42
- blockPatterns: __experimentalGetPatternsByBlockTypes('core/post-content')
46
+ // get pa
47
+ blockPatternsWithPostContentBlockType: __experimentalGetPatternsByBlockTypes('core/post-content'),
48
+ postType: getCurrentPostType()
43
49
  };
44
50
  }, []);
51
+ return (0, _element.useMemo)(() => {
52
+ // filter patterns without postTypes declared if the current postType is page
53
+ // or patterns that declare the current postType in its post type array.
54
+ return blockPatternsWithPostContentBlockType.filter(pattern => {
55
+ return postType === 'page' && !pattern.postTypes || Array.isArray(pattern.postTypes) && pattern.postTypes.includes(postType);
56
+ });
57
+ }, [postType, blockPatternsWithPostContentBlockType]);
58
+ }
59
+
60
+ function PatternSelection(_ref) {
61
+ let {
62
+ onChoosePattern
63
+ } = _ref;
64
+ const blockPatterns = useStartPatterns();
45
65
  const shownBlockPatterns = (0, _compose.useAsyncList)(blockPatterns);
46
66
  const {
47
67
  resetEditorBlocks
@@ -64,16 +84,14 @@ const START_PAGE_MODAL_STATES = {
64
84
 
65
85
  function StartPageOptions() {
66
86
  const [modalState, setModalState] = (0, _element.useState)(START_PAGE_MODAL_STATES.INITIAL);
87
+ const blockPatterns = useStartPatterns();
88
+ const hasStartPattern = blockPatterns.length > 0;
67
89
  const shouldOpenModel = (0, _data.useSelect)(select => {
68
- if (modalState !== START_PAGE_MODAL_STATES.INITIAL) {
90
+ if (!hasStartPattern || modalState !== START_PAGE_MODAL_STATES.INITIAL) {
69
91
  return false;
70
92
  }
71
93
 
72
94
  const {
73
- __experimentalGetPatternsByBlockTypes
74
- } = select(_blockEditor.store);
75
- const {
76
- getCurrentPostType,
77
95
  getEditedPostContent,
78
96
  isEditedPostSaveable
79
97
  } = select(_editor.store);
@@ -81,8 +99,8 @@ function StartPageOptions() {
81
99
  isEditingTemplate,
82
100
  isFeatureActive
83
101
  } = select(_store.store);
84
- return getCurrentPostType() === 'page' && !isEditedPostSaveable() && '' === getEditedPostContent() && !isEditingTemplate() && !isFeatureActive('welcomeGuide') && __experimentalGetPatternsByBlockTypes('core/post-content').length >= 1;
85
- }, [modalState]);
102
+ return !isEditedPostSaveable() && '' === getEditedPostContent() && !isEditingTemplate() && !isFeatureActive('welcomeGuide');
103
+ }, [modalState, hasStartPattern]);
86
104
  (0, _element.useEffect)(() => {
87
105
  if (shouldOpenModel) {
88
106
  setModalState(START_PAGE_MODAL_STATES.PATTERN);
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-post/src/components/start-page-options/index.js"],"names":["PatternSelection","onChoosePattern","blockPatterns","select","__experimentalGetPatternsByBlockTypes","blockEditorStore","shownBlockPatterns","resetEditorBlocks","editorStore","_pattern","blocks","START_PAGE_MODAL_STATES","INITIAL","PATTERN","CLOSED","StartPageOptions","modalState","setModalState","shouldOpenModel","getCurrentPostType","getEditedPostContent","isEditedPostSaveable","isEditingTemplate","isFeatureActive","editPostStore","length"],"mappings":";;;;;;;AAKA;;AAFA;;AACA;;AAEA;;AAIA;;AACA;;AACA;;AAKA;;AAjBA;AACA;AACA;;AAYA;AACA;AACA;AAGA,SAASA,gBAAT,OAAiD;AAAA,MAAtB;AAAEC,IAAAA;AAAF,GAAsB;AAChD,QAAM;AAAEC,IAAAA;AAAF,MAAoB,qBAAaC,MAAF,IAAc;AAClD,UAAM;AAAEC,MAAAA;AAAF,QAA4CD,MAAM,CACvDE,kBADuD,CAAxD;AAGA,WAAO;AACNH,MAAAA,aAAa,EAAEE,qCAAqC,CACnD,mBADmD;AAD9C,KAAP;AAKA,GATyB,EASvB,EATuB,CAA1B;AAUA,QAAME,kBAAkB,GAAG,2BAAcJ,aAAd,CAA3B;AACA,QAAM;AAAEK,IAAAA;AAAF,MAAwB,uBAAaC,aAAb,CAA9B;AACA,SACC,4BAAC,4CAAD;AACC,IAAA,aAAa,EAAGN,aADjB;AAEC,IAAA,aAAa,EAAGI,kBAFjB;AAGC,IAAA,cAAc,EAAG,CAAEG,QAAF,EAAYC,MAAZ,KAAwB;AACxCH,MAAAA,iBAAiB,CAAEG,MAAF,CAAjB;AACAT,MAAAA,eAAe;AACf;AANF,IADD;AAUA;;AAED,MAAMU,uBAAuB,GAAG;AAC/BC,EAAAA,OAAO,EAAE,SADsB;AAE/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Hd;AAIC,IAAA,cAAc,EAAG,MAAM;AACtBG,MAAAA,aAAa,CAAEN,uBAAuB,CAACG,MAA1B,CAAb;AACA;AANF,KAQC;AAAK,IAAA,SAAS,EAAC;AAAf,KACGE,UAAU,KAAKL,uBAAuB,CAACE,OAAvC,IACD,4BAAC,gBAAD;AACC,IAAA,eAAe,EAAG,MAAM;AACvBI,MAAAA,aAAa,CAAEN,uBAAuB,CAACG,MAA1B,CAAb;AACA;AAHF,IAFF,CARD,CADD;AAoBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { Modal } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useState, useEffect } from '@wordpress/element';\nimport {\n\tstore as blockEditorStore,\n\t__experimentalBlockPatternsList as BlockPatternsList,\n} from '@wordpress/block-editor';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useAsyncList } from '@wordpress/compose';\nimport { store as editorStore } from '@wordpress/editor';\n\n/**\n * Internal dependencies\n */\nimport { store as editPostStore } from '../../store';\n\nfunction PatternSelection( { onChoosePattern } ) {\n\tconst { blockPatterns } = useSelect( ( select ) => {\n\t\tconst { __experimentalGetPatternsByBlockTypes } = select(\n\t\t\tblockEditorStore\n\t\t);\n\t\treturn {\n\t\t\tblockPatterns: __experimentalGetPatternsByBlockTypes(\n\t\t\t\t'core/post-content'\n\t\t\t),\n\t\t};\n\t}, [] );\n\tconst shownBlockPatterns = useAsyncList( blockPatterns );\n\tconst { resetEditorBlocks } = useDispatch( editorStore );\n\treturn (\n\t\t<BlockPatternsList\n\t\t\tblockPatterns={ blockPatterns }\n\t\t\tshownPatterns={ shownBlockPatterns }\n\t\t\tonClickPattern={ ( _pattern, blocks ) => {\n\t\t\t\tresetEditorBlocks( blocks );\n\t\t\t\tonChoosePattern();\n\t\t\t} }\n\t\t/>\n\t);\n}\n\nconst START_PAGE_MODAL_STATES = {\n\tINITIAL: 'INITIAL',\n\tPATTERN: 'PATTERN',\n\tCLOSED: 'CLOSED',\n};\n\nexport default function StartPageOptions() {\n\tconst [ modalState, setModalState ] = useState(\n\t\tSTART_PAGE_MODAL_STATES.INITIAL\n\t);\n\tconst shouldOpenModel = useSelect(\n\t\t( select ) => {\n\t\t\tif ( modalState !== START_PAGE_MODAL_STATES.INITIAL ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tconst { __experimentalGetPatternsByBlockTypes } = select(\n\t\t\t\tblockEditorStore\n\t\t\t);\n\t\t\tconst {\n\t\t\t\tgetCurrentPostType,\n\t\t\t\tgetEditedPostContent,\n\t\t\t\tisEditedPostSaveable,\n\t\t\t} = select( editorStore );\n\t\t\tconst { isEditingTemplate, isFeatureActive } = select(\n\t\t\t\teditPostStore\n\t\t\t);\n\t\t\treturn (\n\t\t\t\tgetCurrentPostType() === 'page' &&\n\t\t\t\t! isEditedPostSaveable() &&\n\t\t\t\t'' === getEditedPostContent() &&\n\t\t\t\t! isEditingTemplate() &&\n\t\t\t\t! isFeatureActive( 'welcomeGuide' ) &&\n\t\t\t\t__experimentalGetPatternsByBlockTypes( 'core/post-content' )\n\t\t\t\t\t.length >= 1\n\t\t\t);\n\t\t},\n\t\t[ modalState ]\n\t);\n\n\tuseEffect( () => {\n\t\tif ( shouldOpenModel ) {\n\t\t\tsetModalState( START_PAGE_MODAL_STATES.PATTERN );\n\t\t}\n\t}, [ shouldOpenModel ] );\n\n\tif (\n\t\tmodalState === START_PAGE_MODAL_STATES.INITIAL ||\n\t\tmodalState === START_PAGE_MODAL_STATES.CLOSED\n\t) {\n\t\treturn null;\n\t}\n\treturn (\n\t\t<Modal\n\t\t\tclassName=\"edit-post-start-page-options__modal\"\n\t\t\ttitle={ __( 'Choose a pattern' ) }\n\t\t\tcloseLabel={ __( 'Cancel' ) }\n\t\t\tonRequestClose={ () => {\n\t\t\t\tsetModalState( START_PAGE_MODAL_STATES.CLOSED );\n\t\t\t} }\n\t\t>\n\t\t\t<div className=\"edit-post-start-page-options__modal-content\">\n\t\t\t\t{ modalState === START_PAGE_MODAL_STATES.PATTERN && (\n\t\t\t\t\t<PatternSelection\n\t\t\t\t\t\tonChoosePattern={ () => {\n\t\t\t\t\t\t\tsetModalState( START_PAGE_MODAL_STATES.CLOSED );\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t</Modal>\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/edit-post/src/components/start-page-options/index.js"],"names":["useStartPatterns","blockPatternsWithPostContentBlockType","postType","select","__experimentalGetPatternsByBlockTypes","blockEditorStore","getCurrentPostType","editorStore","filter","pattern","postTypes","Array","isArray","includes","PatternSelection","onChoosePattern","blockPatterns","shownBlockPatterns","resetEditorBlocks","_pattern","blocks","START_PAGE_MODAL_STATES","INITIAL","PATTERN","CLOSED","StartPageOptions","modalState","setModalState","hasStartPattern","length","shouldOpenModel","getEditedPostContent","isEditedPostSaveable","isEditingTemplate","isFeatureActive","editPostStore"],"mappings":";;;;;;;AAKA;;AAFA;;AACA;;AAEA;;AAIA;;AACA;;AACA;;AAKA;;AAjBA;AACA;AACA;;AAYA;AACA;AACA;AAGA,SAASA,gBAAT,GAA4B;AAC3B;AACA;AACA;AACA,QAAM;AAAEC,IAAAA,qCAAF;AAAyCC,IAAAA;AAAzC,MAAsD,qBACzDC,MAAF,IAAc;AACb,UAAM;AAAEC,MAAAA;AAAF,QACLD,MAAM,CAAEE,kBAAF,CADP;AAEA,UAAM;AAAEC,MAAAA;AAAF,QAAyBH,MAAM,CAAEI,aAAF,CAArC;AACA,WAAO;AACN;AACAN,MAAAA,qCAAqC,EACpCG,qCAAqC,CACpC,mBADoC,CAHhC;AAMNF,MAAAA,QAAQ,EAAEI,kBAAkB;AANtB,KAAP;AAQA,GAb0D,EAc3D,EAd2D,CAA5D;AAiBA,SAAO,sBAAS,MAAM;AACrB;AACA;AACA,WAAOL,qCAAqC,CAACO,MAAtC,CAAgDC,OAAF,IAAe;AACnE,aACGP,QAAQ,KAAK,MAAb,IAAuB,CAAEO,OA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,CADP;AAEA,UAAM;AAAE0B,MAAAA,iBAAF;AAAqBC,MAAAA;AAArB,QACL/B,MAAM,CAAEgC,YAAF,CADP;AAEA,WACC,CAAEH,oBAAoB,EAAtB,IACA,OAAOD,oBAAoB,EAD3B,IAEA,CAAEE,iBAAiB,EAFnB,IAGA,CAAEC,eAAe,CAAE,cAAF,CAJlB;AAMA,GAlBsB,EAmBvB,CAAER,UAAF,EAAcE,eAAd,CAnBuB,CAAxB;AAsBA,0BAAW,MAAM;AAChB,QAAKE,eAAL,EAAuB;AACtBH,MAAAA,aAAa,CAAEN,uBAAuB,CAACE,OAA1B,CAAb;AACA;AACD,GAJD,EAIG,CAAEO,eAAF,CAJH;;AAMA,MACCJ,UAAU,KAAKL,uBAAuB,CAACC,OAAvC,IACAI,UAAU,KAAKL,uBAAuB,CAACG,MAFxC,EAGE;AACD,WAAO,IAAP;AACA;;AACD,SACC,4BAAC,iBAAD;AACC,IAAA,SAAS,EAAC,qCADX;AAEC,IAAA,KAAK,EAAG,cAAI,kBAAJ,CAFT;AAGC,IAAA,UAAU,EAAG,cAAI,QAAJ,CAHd;AAIC,IAAA,cAAc,EAAG,MAAM;AACtBG,MAAAA,aAAa,CAAEN,uBAAuB,CAACG,MAA1B,CAAb;AACA;AANF,KAQC;AAAK,IAAA,SAAS,EAAC;AAAf,KACGE,UAAU,KAAKL,uBAAuB,CAACE,OAAvC,IACD,4BAAC,gBAAD;AACC,IAAA,eAAe,EAAG,MAAM;AACvBI,MAAAA,aAAa,CAAEN,uBAAuB,CAACG,MAA1B,CAAb;AACA;AAHF,IAFF,CARD,CADD;AAoBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { Modal } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useState, useEffect, useMemo } from '@wordpress/element';\nimport {\n\tstore as blockEditorStore,\n\t__experimentalBlockPatternsList as BlockPatternsList,\n} from '@wordpress/block-editor';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useAsyncList } from '@wordpress/compose';\nimport { store as editorStore } from '@wordpress/editor';\n\n/**\n * Internal dependencies\n */\nimport { store as editPostStore } from '../../store';\n\nfunction useStartPatterns() {\n\t// A pattern is a start pattern if it includes 'core/post-content' in its blockTypes,\n\t// and it has no postTypes declares and the current post type is page or if\n\t// the current post type is part of the postTypes declared.\n\tconst { blockPatternsWithPostContentBlockType, postType } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { __experimentalGetPatternsByBlockTypes } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst { getCurrentPostType } = select( editorStore );\n\t\t\treturn {\n\t\t\t\t// get pa\n\t\t\t\tblockPatternsWithPostContentBlockType:\n\t\t\t\t\t__experimentalGetPatternsByBlockTypes(\n\t\t\t\t\t\t'core/post-content'\n\t\t\t\t\t),\n\t\t\t\tpostType: getCurrentPostType(),\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\n\treturn useMemo( () => {\n\t\t// filter patterns without postTypes declared if the current postType is page\n\t\t// or patterns that declare the current postType in its post type array.\n\t\treturn blockPatternsWithPostContentBlockType.filter( ( pattern ) => {\n\t\t\treturn (\n\t\t\t\t( postType === 'page' && ! pattern.postTypes ) ||\n\t\t\t\t( Array.isArray( pattern.postTypes ) &&\n\t\t\t\t\tpattern.postTypes.includes( postType ) )\n\t\t\t);\n\t\t} );\n\t}, [ postType, blockPatternsWithPostContentBlockType ] );\n}\n\nfunction PatternSelection( { onChoosePattern } ) {\n\tconst blockPatterns = useStartPatterns();\n\tconst shownBlockPatterns = useAsyncList( blockPatterns );\n\tconst { resetEditorBlocks } = useDispatch( editorStore );\n\treturn (\n\t\t<BlockPatternsList\n\t\t\tblockPatterns={ blockPatterns }\n\t\t\tshownPatterns={ shownBlockPatterns }\n\t\t\tonClickPattern={ ( _pattern, blocks ) => {\n\t\t\t\tresetEditorBlocks( blocks );\n\t\t\t\tonChoosePattern();\n\t\t\t} }\n\t\t/>\n\t);\n}\n\nconst START_PAGE_MODAL_STATES = {\n\tINITIAL: 'INITIAL',\n\tPATTERN: 'PATTERN',\n\tCLOSED: 'CLOSED',\n};\n\nexport default function StartPageOptions() {\n\tconst [ modalState, setModalState ] = useState(\n\t\tSTART_PAGE_MODAL_STATES.INITIAL\n\t);\n\tconst blockPatterns = useStartPatterns();\n\tconst hasStartPattern = blockPatterns.length > 0;\n\tconst shouldOpenModel = useSelect(\n\t\t( select ) => {\n\t\t\tif (\n\t\t\t\t! hasStartPattern ||\n\t\t\t\tmodalState !== START_PAGE_MODAL_STATES.INITIAL\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tconst { getEditedPostContent, isEditedPostSaveable } =\n\t\t\t\tselect( editorStore );\n\t\t\tconst { isEditingTemplate, isFeatureActive } =\n\t\t\t\tselect( editPostStore );\n\t\t\treturn (\n\t\t\t\t! isEditedPostSaveable() &&\n\t\t\t\t'' === getEditedPostContent() &&\n\t\t\t\t! isEditingTemplate() &&\n\t\t\t\t! isFeatureActive( 'welcomeGuide' )\n\t\t\t);\n\t\t},\n\t\t[ modalState, hasStartPattern ]\n\t);\n\n\tuseEffect( () => {\n\t\tif ( shouldOpenModel ) {\n\t\t\tsetModalState( START_PAGE_MODAL_STATES.PATTERN );\n\t\t}\n\t}, [ shouldOpenModel ] );\n\n\tif (\n\t\tmodalState === START_PAGE_MODAL_STATES.INITIAL ||\n\t\tmodalState === START_PAGE_MODAL_STATES.CLOSED\n\t) {\n\t\treturn null;\n\t}\n\treturn (\n\t\t<Modal\n\t\t\tclassName=\"edit-post-start-page-options__modal\"\n\t\t\ttitle={ __( 'Choose a pattern' ) }\n\t\t\tcloseLabel={ __( 'Cancel' ) }\n\t\t\tonRequestClose={ () => {\n\t\t\t\tsetModalState( START_PAGE_MODAL_STATES.CLOSED );\n\t\t\t} }\n\t\t>\n\t\t\t<div className=\"edit-post-start-page-options__modal-content\">\n\t\t\t\t{ modalState === START_PAGE_MODAL_STATES.PATTERN && (\n\t\t\t\t\t<PatternSelection\n\t\t\t\t\t\tonChoosePattern={ () => {\n\t\t\t\t\t\t\tsetModalState( START_PAGE_MODAL_STATES.CLOSED );\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t</Modal>\n\t);\n}\n"]}
@@ -8,8 +8,6 @@ exports.default = void 0;
8
8
 
9
9
  var _element = require("@wordpress/element");
10
10
 
11
- var _lodash = require("lodash");
12
-
13
11
  var _i18n = require("@wordpress/i18n");
14
12
 
15
13
  var _components = require("@wordpress/components");
@@ -22,10 +20,6 @@ var _keyboardShortcuts = require("@wordpress/keyboard-shortcuts");
22
20
 
23
21
  var _store = require("../../store");
24
22
 
25
- /**
26
- * External dependencies
27
- */
28
-
29
23
  /**
30
24
  * WordPress dependencies
31
25
  */
@@ -33,9 +27,11 @@ var _store = require("../../store");
33
27
  /**
34
28
  * Internal dependencies
35
29
  */
30
+ const noop = () => {};
31
+
36
32
  function BlockInspectorButton(_ref) {
37
33
  let {
38
- onClick = _lodash.noop,
34
+ onClick = noop,
39
35
  small = false
40
36
  } = _ref;
41
37
  const {
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-post/src/components/visual-editor/block-inspector-button.js"],"names":["BlockInspectorButton","onClick","noop","small","shortcut","areAdvancedSettingsOpened","select","keyboardShortcutsStore","getShortcutRepresentation","editPostStore","getActiveGeneralSidebarName","openGeneralSidebar","closeGeneralSidebar","label"],"mappings":";;;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AAjBA;AACA;AACA;;AAGA;AACA;AACA;;AAOA;AACA;AACA;AAGO,SAASA,oBAAT,OAAmE;AAAA,MAApC;AAAEC,IAAAA,OAAO,GAAGC,YAAZ;AAAkBC,IAAAA,KAAK,GAAG;AAA1B,GAAoC;AACzE,QAAM;AAAEC,IAAAA,QAAF;AAAYC,IAAAA;AAAZ,MAA0C,qBAC7CC,MAAF,KAAgB;AACfF,IAAAA,QAAQ,EAAEE,MAAM,CACfC,wBADe,CAAN,CAERC,yBAFQ,CAEmB,+BAFnB,CADK;AAIfH,IAAAA,yBAAyB,EACxBC,MAAM,CAAEG,YAAF,CAAN,CAAwBC,2BAAxB,OACA;AANc,GAAhB,CAD+C,EAS/C,EAT+C,CAAhD;AAWA,QAAM;AAAEC,IAAAA,kBAAF;AAAsBC,IAAAA;AAAtB,MAA8C,uBACnDH,YADmD,CAApD;AAIA,QAAMI,KAAK,GAAGR,yBAAyB,GACpC,cAAI,oBAAJ,CADoC,GAEpC,cAAI,oBAAJ,CAFH;AAIA,SACC,4BAAC,oBAAD;AACC,IAAA,OAAO,EAAG,MAAM;AACf,UAAKA,yBAAL,EAAiC;AAChCO,QAAAA,mBAAmB;AACnB,yBAAO,cAAI,uBAAJ,CAAP;AACA,OAHD,MAGO;AACND,QAAAA,kBAAkB,CAAE,iBAAF,CAAlB;AACA,yBACC,cACC,4EADD,CADD;AAKA;;AACDV,MAAAA,OAAO;AACP,KAdF;AAeC,IAAA,QAAQ,EAAGG;AAfZ,KAiBG,CAAED,KAAF,IAAWU,KAjBd,CADD;AAqBA;;eAEcb,oB","sourcesContent":["/**\n * External dependencies\n */\nimport { noop } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { MenuItem } from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { speak } from '@wordpress/a11y';\nimport { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n\n/**\n * Internal dependencies\n */\nimport { store as editPostStore } from '../../store';\n\nexport function BlockInspectorButton( { onClick = noop, small = false } ) {\n\tconst { shortcut, areAdvancedSettingsOpened } = useSelect(\n\t\t( select ) => ( {\n\t\t\tshortcut: select(\n\t\t\t\tkeyboardShortcutsStore\n\t\t\t).getShortcutRepresentation( 'core/edit-post/toggle-sidebar' ),\n\t\t\tareAdvancedSettingsOpened:\n\t\t\t\tselect( editPostStore ).getActiveGeneralSidebarName() ===\n\t\t\t\t'edit-post/block',\n\t\t} ),\n\t\t[]\n\t);\n\tconst { openGeneralSidebar, closeGeneralSidebar } = useDispatch(\n\t\teditPostStore\n\t);\n\n\tconst label = areAdvancedSettingsOpened\n\t\t? __( 'Hide more settings' )\n\t\t: __( 'Show more settings' );\n\n\treturn (\n\t\t<MenuItem\n\t\t\tonClick={ () => {\n\t\t\t\tif ( areAdvancedSettingsOpened ) {\n\t\t\t\t\tcloseGeneralSidebar();\n\t\t\t\t\tspeak( __( 'Block settings closed' ) );\n\t\t\t\t} else {\n\t\t\t\t\topenGeneralSidebar( 'edit-post/block' );\n\t\t\t\t\tspeak(\n\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t'Additional settings are now available in the Editor block settings sidebar'\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tonClick();\n\t\t\t} }\n\t\t\tshortcut={ shortcut }\n\t\t>\n\t\t\t{ ! small && label }\n\t\t</MenuItem>\n\t);\n}\n\nexport default BlockInspectorButton;\n"]}
1
+ {"version":3,"sources":["@wordpress/edit-post/src/components/visual-editor/block-inspector-button.js"],"names":["noop","BlockInspectorButton","onClick","small","shortcut","areAdvancedSettingsOpened","select","keyboardShortcutsStore","getShortcutRepresentation","editPostStore","getActiveGeneralSidebarName","openGeneralSidebar","closeGeneralSidebar","label"],"mappings":";;;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AAZA;AACA;AACA;;AAOA;AACA;AACA;AAGA,MAAMA,IAAI,GAAG,MAAM,CAAE,CAArB;;AAEO,SAASC,oBAAT,OAAmE;AAAA,MAApC;AAAEC,IAAAA,OAAO,GAAGF,IAAZ;AAAkBG,IAAAA,KAAK,GAAG;AAA1B,GAAoC;AACzE,QAAM;AAAEC,IAAAA,QAAF;AAAYC,IAAAA;AAAZ,MAA0C,qBAC7CC,MAAF,KAAgB;AACfF,IAAAA,QAAQ,EAAEE,MAAM,CACfC,wBADe,CAAN,CAERC,yBAFQ,CAEmB,+BAFnB,CADK;AAIfH,IAAAA,yBAAyB,EACxBC,MAAM,CAAEG,YAAF,CAAN,CAAwBC,2BAAxB,OACA;AANc,GAAhB,CAD+C,EAS/C,EAT+C,CAAhD;AAWA,QAAM;AAAEC,IAAAA,kBAAF;AAAsBC,IAAAA;AAAtB,MACL,uBAAaH,YAAb,CADD;AAGA,QAAMI,KAAK,GAAGR,yBAAyB,GACpC,cAAI,oBAAJ,CADoC,GAEpC,cAAI,oBAAJ,CAFH;AAIA,SACC,4BAAC,oBAAD;AACC,IAAA,OAAO,EAAG,MAAM;AACf,UAAKA,yBAAL,EAAiC;AAChCO,QAAAA,mBAAmB;AACnB,yBAAO,cAAI,uBAAJ,CAAP;AACA,OAHD,MAGO;AACND,QAAAA,kBAAkB,CAAE,iBAAF,CAAlB;AACA,yBACC,cACC,4EADD,CADD;AAKA;;AACDT,MAAAA,OAAO;AACP,KAdF;AAeC,IAAA,QAAQ,EAAGE;AAfZ,KAiBG,CAAED,KAAF,IAAWU,KAjBd,CADD;AAqBA;;eAEcZ,oB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { MenuItem } from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { speak } from '@wordpress/a11y';\nimport { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n\n/**\n * Internal dependencies\n */\nimport { store as editPostStore } from '../../store';\n\nconst noop = () => {};\n\nexport function BlockInspectorButton( { onClick = noop, small = false } ) {\n\tconst { shortcut, areAdvancedSettingsOpened } = useSelect(\n\t\t( select ) => ( {\n\t\t\tshortcut: select(\n\t\t\t\tkeyboardShortcutsStore\n\t\t\t).getShortcutRepresentation( 'core/edit-post/toggle-sidebar' ),\n\t\t\tareAdvancedSettingsOpened:\n\t\t\t\tselect( editPostStore ).getActiveGeneralSidebarName() ===\n\t\t\t\t'edit-post/block',\n\t\t} ),\n\t\t[]\n\t);\n\tconst { openGeneralSidebar, closeGeneralSidebar } =\n\t\tuseDispatch( editPostStore );\n\n\tconst label = areAdvancedSettingsOpened\n\t\t? __( 'Hide more settings' )\n\t\t: __( 'Show more settings' );\n\n\treturn (\n\t\t<MenuItem\n\t\t\tonClick={ () => {\n\t\t\t\tif ( areAdvancedSettingsOpened ) {\n\t\t\t\t\tcloseGeneralSidebar();\n\t\t\t\t\tspeak( __( 'Block settings closed' ) );\n\t\t\t\t} else {\n\t\t\t\t\topenGeneralSidebar( 'edit-post/block' );\n\t\t\t\t\tspeak(\n\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t'Additional settings are now available in the Editor block settings sidebar'\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tonClick();\n\t\t\t} }\n\t\t\tshortcut={ shortcut }\n\t\t>\n\t\t\t{ ! small && label }\n\t\t</MenuItem>\n\t);\n}\n\nexport default BlockInspectorButton;\n"]}