@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
@@ -21,6 +21,7 @@ import PostFormat from '../post-format';
21
21
  import PostPendingStatus from '../post-pending-status';
22
22
  import PluginPostStatusInfo from '../plugin-post-status-info';
23
23
  import { store as editPostStore } from '../../../store';
24
+ import PostTemplate from '../post-template';
24
25
  /**
25
26
  * Module Constants
26
27
  */
@@ -34,10 +35,10 @@ function PostStatus(_ref) {
34
35
  } = _ref;
35
36
  return createElement(PanelBody, {
36
37
  className: "edit-post-post-status",
37
- title: __('Status & visibility'),
38
+ title: __('Summary'),
38
39
  opened: isOpened,
39
40
  onToggle: onTogglePanel
40
- }, createElement(PluginPostStatusInfo.Slot, null, fills => createElement(Fragment, null, createElement(PostVisibility, null), createElement(PostSchedule, null), createElement(PostFormat, null), createElement(PostSticky, null), createElement(PostPendingStatus, null), createElement(PostSlug, null), createElement(PostAuthor, null), fills, createElement(PostTrash, null))));
41
+ }, createElement(PluginPostStatusInfo.Slot, null, fills => createElement(Fragment, null, createElement(PostVisibility, null), createElement(PostSchedule, null), createElement(PostTemplate, null), createElement(PostFormat, null), createElement(PostSticky, null), createElement(PostPendingStatus, null), createElement(PostSlug, null), createElement(PostAuthor, null), fills, createElement(PostTrash, null))));
41
42
  }
42
43
 
43
44
  export default compose([withSelect(select => {
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-post/src/components/sidebar/post-status/index.js"],"names":["__","PanelBody","withSelect","withDispatch","compose","ifCondition","PostVisibility","PostTrash","PostSchedule","PostSticky","PostAuthor","PostSlug","PostFormat","PostPendingStatus","PluginPostStatusInfo","store","editPostStore","PANEL_NAME","PostStatus","isOpened","onTogglePanel","fills","select","isEditorPanelRemoved","isEditorPanelOpened","isRemoved","dispatch","toggleEditorPanelOpened"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SAASC,SAAT,QAA0B,uBAA1B;AACA,SAASC,UAAT,EAAqBC,YAArB,QAAyC,iBAAzC;AACA,SAASC,OAAT,EAAkBC,WAAlB,QAAqC,oBAArC;AAEA;AACA;AACA;;AACA,OAAOC,cAAP,MAA2B,oBAA3B;AACA,OAAOC,SAAP,MAAsB,eAAtB;AACA,OAAOC,YAAP,MAAyB,kBAAzB;AACA,OAAOC,UAAP,MAAuB,gBAAvB;AACA,OAAOC,UAAP,MAAuB,gBAAvB;AACA,OAAOC,QAAP,MAAqB,cAArB;AACA,OAAOC,UAAP,MAAuB,gBAAvB;AACA,OAAOC,iBAAP,MAA8B,wBAA9B;AACA,OAAOC,oBAAP,MAAiC,4BAAjC;AACA,SAASC,KAAK,IAAIC,aAAlB,QAAuC,gBAAvC;AAEA;AACA;AACA;;AACA,MAAMC,UAAU,GAAG,aAAnB;;AAEA,SAASC,UAAT,OAAmD;AAAA,MAA9B;AAAEC,IAAAA,QAAF;AAAYC,IAAAA;AAAZ,GAA8B;AAClD,SACC,cAAC,SAAD;AACC,IAAA,SAAS,EAAC,uBADX;AAEC,IAAA,KAAK,EAAGpB,EAAE,CAAE,qBAAF,CAFX;AAGC,IAAA,MAAM,EAAGmB,QAHV;AAIC,IAAA,QAAQ,EAAGC;AAJZ,KAMC,cAAC,oBAAD,CAAsB,IAAtB,QACKC,KAAF,IACD,8BACC,cAAC,cAAD,OADD,EAEC,cAAC,YAAD,OAFD,EAGC,cAAC,UAAD,OAHD,EAIC,cAAC,UAAD,OAJD,EAKC,cAAC,iBAAD,OALD,EAMC,cAAC,QAAD,OAND,EAOC,cAAC,UAAD,OAPD,EAQGA,KARH,EASC,cAAC,SAAD,OATD,CAFF,CAND,CADD;AAwBA;;AAED,eAAejB,OAAO,CAAE,CACvBF,UAAU,CAAIoB,MAAF,IAAc;AACzB;AACA;AACA,QAAM;AAAEC,IAAAA,oBAAF;AAAwBC,IAAAA;AAAxB,MACLF,MAAM,CAAEN,aAAF,CADP;AAEA,SAAO;AACNS,IAAAA,SAAS,EAAEF,oBAAoB,CAAEN,UAAF,CADzB;AAENE,IAAAA,QAAQ,EAAEK,mBAAmB,CAAEP,UAAF;AAFvB,GAAP;AAIA,CATS,CADa,EAWvBZ,WAAW,CAAE;AAAA,MAAE;AAAEoB,IAAAA;AAAF,GAAF;AAAA,SAAqB,CAAEA,SAAvB;AAAA,CAAF,CAXY,EAYvBtB,YAAY,CAAIuB,QAAF,KAAkB;AAC/BN,EAAAA,aAAa,GAAG;AACf,WAAOM,QAAQ,CAAEV,aAAF,CAAR,CAA0BW,uBAA1B,CACNV,UADM,CAAP;AAGA;;AAL8B,CAAlB,CAAF,CAZW,CAAF,CAAP,CAmBVC,UAnBU,CAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { PanelBody } from '@wordpress/components';\nimport { withSelect, withDispatch } from '@wordpress/data';\nimport { compose, ifCondition } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport PostVisibility from '../post-visibility';\nimport PostTrash from '../post-trash';\nimport PostSchedule from '../post-schedule';\nimport PostSticky from '../post-sticky';\nimport PostAuthor from '../post-author';\nimport PostSlug from '../post-slug';\nimport PostFormat from '../post-format';\nimport PostPendingStatus from '../post-pending-status';\nimport PluginPostStatusInfo from '../plugin-post-status-info';\nimport { store as editPostStore } from '../../../store';\n\n/**\n * Module Constants\n */\nconst PANEL_NAME = 'post-status';\n\nfunction PostStatus( { isOpened, onTogglePanel } ) {\n\treturn (\n\t\t<PanelBody\n\t\t\tclassName=\"edit-post-post-status\"\n\t\t\ttitle={ __( 'Status & visibility' ) }\n\t\t\topened={ isOpened }\n\t\t\tonToggle={ onTogglePanel }\n\t\t>\n\t\t\t<PluginPostStatusInfo.Slot>\n\t\t\t\t{ ( fills ) => (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<PostVisibility />\n\t\t\t\t\t\t<PostSchedule />\n\t\t\t\t\t\t<PostFormat />\n\t\t\t\t\t\t<PostSticky />\n\t\t\t\t\t\t<PostPendingStatus />\n\t\t\t\t\t\t<PostSlug />\n\t\t\t\t\t\t<PostAuthor />\n\t\t\t\t\t\t{ fills }\n\t\t\t\t\t\t<PostTrash />\n\t\t\t\t\t</>\n\t\t\t\t) }\n\t\t\t</PluginPostStatusInfo.Slot>\n\t\t</PanelBody>\n\t);\n}\n\nexport default compose( [\n\twithSelect( ( select ) => {\n\t\t// We use isEditorPanelRemoved to hide the panel if it was programatically removed. We do\n\t\t// not use isEditorPanelEnabled since this panel should not be disabled through the UI.\n\t\tconst { isEditorPanelRemoved, isEditorPanelOpened } =\n\t\t\tselect( editPostStore );\n\t\treturn {\n\t\t\tisRemoved: isEditorPanelRemoved( PANEL_NAME ),\n\t\t\tisOpened: isEditorPanelOpened( PANEL_NAME ),\n\t\t};\n\t} ),\n\tifCondition( ( { isRemoved } ) => ! isRemoved ),\n\twithDispatch( ( dispatch ) => ( {\n\t\tonTogglePanel() {\n\t\t\treturn dispatch( editPostStore ).toggleEditorPanelOpened(\n\t\t\t\tPANEL_NAME\n\t\t\t);\n\t\t},\n\t} ) ),\n] )( PostStatus );\n"]}
1
+ {"version":3,"sources":["@wordpress/edit-post/src/components/sidebar/post-status/index.js"],"names":["__","PanelBody","withSelect","withDispatch","compose","ifCondition","PostVisibility","PostTrash","PostSchedule","PostSticky","PostAuthor","PostSlug","PostFormat","PostPendingStatus","PluginPostStatusInfo","store","editPostStore","PostTemplate","PANEL_NAME","PostStatus","isOpened","onTogglePanel","fills","select","isEditorPanelRemoved","isEditorPanelOpened","isRemoved","dispatch","toggleEditorPanelOpened"],"mappings":";;AAAA;AACA;AACA;AACA,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AAM;AAAEC,IAAAA,oBAAF;AAAwBC,IAAAA;AAAxB,MACLF,MAAM,CAAEP,aAAF,CADP;AAEA,SAAO;AACNU,IAAAA,SAAS,EAAEF,oBAAoB,CAAEN,UAAF,CADzB;AAENE,IAAAA,QAAQ,EAAEK,mBAAmB,CAAEP,UAAF;AAFvB,GAAP;AAIA,CATS,CADa,EAWvBb,WAAW,CAAE;AAAA,MAAE;AAAEqB,IAAAA;AAAF,GAAF;AAAA,SAAqB,CAAEA,SAAvB;AAAA,CAAF,CAXY,EAYvBvB,YAAY,CAAIwB,QAAF,KAAkB;AAC/BN,EAAAA,aAAa,GAAG;AACf,WAAOM,QAAQ,CAAEX,aAAF,CAAR,CAA0BY,uBAA1B,CACNV,UADM,CAAP;AAGA;;AAL8B,CAAlB,CAAF,CAZW,CAAF,CAAP,CAmBVC,UAnBU,CAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { PanelBody } from '@wordpress/components';\nimport { withSelect, withDispatch } from '@wordpress/data';\nimport { compose, ifCondition } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport PostVisibility from '../post-visibility';\nimport PostTrash from '../post-trash';\nimport PostSchedule from '../post-schedule';\nimport PostSticky from '../post-sticky';\nimport PostAuthor from '../post-author';\nimport PostSlug from '../post-slug';\nimport PostFormat from '../post-format';\nimport PostPendingStatus from '../post-pending-status';\nimport PluginPostStatusInfo from '../plugin-post-status-info';\nimport { store as editPostStore } from '../../../store';\nimport PostTemplate from '../post-template';\n\n/**\n * Module Constants\n */\nconst PANEL_NAME = 'post-status';\n\nfunction PostStatus( { isOpened, onTogglePanel } ) {\n\treturn (\n\t\t<PanelBody\n\t\t\tclassName=\"edit-post-post-status\"\n\t\t\ttitle={ __( 'Summary' ) }\n\t\t\topened={ isOpened }\n\t\t\tonToggle={ onTogglePanel }\n\t\t>\n\t\t\t<PluginPostStatusInfo.Slot>\n\t\t\t\t{ ( fills ) => (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<PostVisibility />\n\t\t\t\t\t\t<PostSchedule />\n\t\t\t\t\t\t<PostTemplate />\n\t\t\t\t\t\t<PostFormat />\n\t\t\t\t\t\t<PostSticky />\n\t\t\t\t\t\t<PostPendingStatus />\n\t\t\t\t\t\t<PostSlug />\n\t\t\t\t\t\t<PostAuthor />\n\t\t\t\t\t\t{ fills }\n\t\t\t\t\t\t<PostTrash />\n\t\t\t\t\t</>\n\t\t\t\t) }\n\t\t\t</PluginPostStatusInfo.Slot>\n\t\t</PanelBody>\n\t);\n}\n\nexport default compose( [\n\twithSelect( ( select ) => {\n\t\t// We use isEditorPanelRemoved to hide the panel if it was programatically removed. We do\n\t\t// not use isEditorPanelEnabled since this panel should not be disabled through the UI.\n\t\tconst { isEditorPanelRemoved, isEditorPanelOpened } =\n\t\t\tselect( editPostStore );\n\t\treturn {\n\t\t\tisRemoved: isEditorPanelRemoved( PANEL_NAME ),\n\t\t\tisOpened: isEditorPanelOpened( PANEL_NAME ),\n\t\t};\n\t} ),\n\tifCondition( ( { isRemoved } ) => ! isRemoved ),\n\twithDispatch( ( dispatch ) => ( {\n\t\tonTogglePanel() {\n\t\t\treturn dispatch( editPostStore ).toggleEditorPanelOpened(\n\t\t\t\tPANEL_NAME\n\t\t\t);\n\t\t},\n\t} ) ),\n] )( PostStatus );\n"]}
@@ -0,0 +1,104 @@
1
+ import { createElement } from "@wordpress/element";
2
+
3
+ /**
4
+ * WordPress dependencies
5
+ */
6
+ import { useSelect, useDispatch } from '@wordpress/data';
7
+ import { store as editorStore } from '@wordpress/editor';
8
+ import { useState } from '@wordpress/element';
9
+ import { serialize, createBlock } from '@wordpress/blocks';
10
+ import { Modal, Flex, FlexItem, TextControl, Button } from '@wordpress/components';
11
+ import { __ } from '@wordpress/i18n';
12
+ import { cleanForSlug } from '@wordpress/url';
13
+ /**
14
+ * Internal dependencies
15
+ */
16
+
17
+ import { store as editPostStore } from '../../../store';
18
+
19
+ const DEFAULT_TITLE = __('Custom Template');
20
+
21
+ export default function PostTemplateCreateModal(_ref) {
22
+ let {
23
+ onClose
24
+ } = _ref;
25
+ const defaultBlockTemplate = useSelect(select => select(editorStore).getEditorSettings().defaultBlockTemplate, []);
26
+ const {
27
+ __unstableCreateTemplate,
28
+ __unstableSwitchToTemplateMode
29
+ } = useDispatch(editPostStore);
30
+ const [title, setTitle] = useState('');
31
+ const [isBusy, setIsBusy] = useState(false);
32
+
33
+ const cancel = () => {
34
+ setTitle('');
35
+ onClose();
36
+ };
37
+
38
+ const submit = async event => {
39
+ event.preventDefault();
40
+
41
+ if (isBusy) {
42
+ return;
43
+ }
44
+
45
+ setIsBusy(true);
46
+ const newTemplateContent = defaultBlockTemplate !== null && defaultBlockTemplate !== void 0 ? defaultBlockTemplate : serialize([createBlock('core/group', {
47
+ tagName: 'header',
48
+ layout: {
49
+ inherit: true
50
+ }
51
+ }, [createBlock('core/site-title'), createBlock('core/site-tagline')]), createBlock('core/separator'), createBlock('core/group', {
52
+ tagName: 'main'
53
+ }, [createBlock('core/group', {
54
+ layout: {
55
+ inherit: true
56
+ }
57
+ }, [createBlock('core/post-title')]), createBlock('core/post-content', {
58
+ layout: {
59
+ inherit: true
60
+ }
61
+ })])]);
62
+ await __unstableCreateTemplate({
63
+ slug: cleanForSlug(title || DEFAULT_TITLE),
64
+ content: newTemplateContent,
65
+ title: title || DEFAULT_TITLE
66
+ });
67
+ setIsBusy(false);
68
+ cancel();
69
+
70
+ __unstableSwitchToTemplateMode(true);
71
+ };
72
+
73
+ return createElement(Modal, {
74
+ title: __('Create custom template'),
75
+ closeLabel: __('Close'),
76
+ onRequestClose: cancel,
77
+ className: "edit-post-post-template__create-modal"
78
+ }, createElement("form", {
79
+ className: "edit-post-post-template__create-form",
80
+ onSubmit: submit
81
+ }, createElement(Flex, {
82
+ align: "flex-start",
83
+ gap: 8
84
+ }, createElement(FlexItem, null, createElement(TextControl, {
85
+ label: __('Name'),
86
+ value: title,
87
+ onChange: setTitle,
88
+ placeholder: DEFAULT_TITLE,
89
+ disabled: isBusy,
90
+ help: __('Describe the purpose of the template, e.g. "Full Width". Custom templates can be applied to any post or page.')
91
+ }))), createElement(Flex, {
92
+ justify: "flex-end",
93
+ expanded: false
94
+ }, createElement(FlexItem, null, createElement(Button, {
95
+ variant: "tertiary",
96
+ onClick: cancel
97
+ }, __('Cancel'))), createElement(FlexItem, null, createElement(Button, {
98
+ variant: "primary",
99
+ type: "submit",
100
+ isBusy: isBusy,
101
+ "aria-disabled": isBusy
102
+ }, __('Create'))))));
103
+ }
104
+ //# sourceMappingURL=create-modal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/edit-post/src/components/sidebar/post-template/create-modal.js"],"names":["useSelect","useDispatch","store","editorStore","useState","serialize","createBlock","Modal","Flex","FlexItem","TextControl","Button","__","cleanForSlug","editPostStore","DEFAULT_TITLE","PostTemplateCreateModal","onClose","defaultBlockTemplate","select","getEditorSettings","__unstableCreateTemplate","__unstableSwitchToTemplateMode","title","setTitle","isBusy","setIsBusy","cancel","submit","event","preventDefault","newTemplateContent","tagName","layout","inherit","slug","content"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,KAAK,IAAIC,WAAlB,QAAqC,mBAArC;AACA,SAASC,QAAT,QAAyB,oBAAzB;AACA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,mBAAvC;AACA,SACCC,KADD,EAECC,IAFD,EAGCC,QAHD,EAICC,WAJD,EAKCC,MALD,QAMO,uBANP;AAOA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,YAAT,QAA6B,gBAA7B;AAEA;AACA;AACA;;AACA,SAASX,KAAK,IAAIY,aAAlB,QAAuC,gBAAvC;;AAEA,MAAMC,aAAa,GAAGH,EAAE,CAAE,iBAAF,CAAxB;;AAEA,eAAe,SAASI,uBAAT,OAAgD;AAAA,MAAd;AAAEC,IAAAA;AAAF,GAAc;AAC9D,QAAMC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ACC,cAAC,MAAD;AACC,IAAA,OAAO,EAAC,SADT;AAEC,IAAA,IAAI,EAAC,QAFN;AAGC,IAAA,MAAM,EAAGa,MAHV;AAIC,qBAAgBA;AAJjB,KAMGb,EAAE,CAAE,QAAF,CANL,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,106 @@
1
+ import { createElement } from "@wordpress/element";
2
+
3
+ /**
4
+ * WordPress dependencies
5
+ */
6
+ import { useState, useMemo } from '@wordpress/element';
7
+ import { __experimentalInspectorPopoverHeader as InspectorPopoverHeader } from '@wordpress/block-editor';
8
+ import { __ } from '@wordpress/i18n';
9
+ import { addTemplate } from '@wordpress/icons';
10
+ import { Notice, SelectControl, Button } from '@wordpress/components';
11
+ import { useSelect, useDispatch } from '@wordpress/data';
12
+ import { store as editorStore } from '@wordpress/editor';
13
+ import { store as coreStore } from '@wordpress/core-data';
14
+ /**
15
+ * Internal dependencies
16
+ */
17
+
18
+ import { store as editPostStore } from '../../../store';
19
+ import PostTemplateCreateModal from './create-modal';
20
+ export default function PostTemplateForm(_ref) {
21
+ var _options$find, _selectedOption$value;
22
+
23
+ let {
24
+ onClose
25
+ } = _ref;
26
+ const {
27
+ isPostsPage,
28
+ availableTemplates,
29
+ fetchedTemplates,
30
+ selectedTemplateSlug,
31
+ canCreate,
32
+ canEdit
33
+ } = useSelect(select => {
34
+ const editorSettings = select(editorStore).getEditorSettings();
35
+ const siteSettings = select(coreStore).getEntityRecord('root', 'site');
36
+
37
+ const _isPostsPage = select(editorStore).getCurrentPostId() === (siteSettings === null || siteSettings === void 0 ? void 0 : siteSettings.page_for_posts);
38
+
39
+ const canCreateTemplates = select(coreStore).canUser('create', 'templates');
40
+ return {
41
+ isPostsPage: _isPostsPage,
42
+ availableTemplates: editorSettings.availableTemplates,
43
+ fetchedTemplates: select(coreStore).getEntityRecords('postType', 'wp_template', {
44
+ post_type: select(editorStore).getCurrentPostType(),
45
+ per_page: -1
46
+ }),
47
+ selectedTemplateSlug: select(editorStore).getEditedPostAttribute('template'),
48
+ canCreate: canCreateTemplates && !_isPostsPage,
49
+ canEdit: canCreateTemplates && editorSettings.supportsTemplateMode && !!select(editPostStore).getEditedPostTemplate()
50
+ };
51
+ }, []);
52
+ const options = useMemo(() => Object.entries({ ...availableTemplates,
53
+ ...Object.fromEntries((fetchedTemplates !== null && fetchedTemplates !== void 0 ? fetchedTemplates : []).map(_ref2 => {
54
+ let {
55
+ slug,
56
+ title
57
+ } = _ref2;
58
+ return [slug, title.rendered];
59
+ }))
60
+ }).map(_ref3 => {
61
+ let [slug, title] = _ref3;
62
+ return {
63
+ value: slug,
64
+ label: title
65
+ };
66
+ }), [availableTemplates, fetchedTemplates]);
67
+ 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.
68
+
69
+ const {
70
+ editPost
71
+ } = useDispatch(editorStore);
72
+ const {
73
+ __unstableSwitchToTemplateMode
74
+ } = useDispatch(editPostStore);
75
+ const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
76
+ return createElement("div", {
77
+ className: "edit-post-post-template__form"
78
+ }, createElement(InspectorPopoverHeader, {
79
+ title: __('Template'),
80
+ help: __('Templates define the way content is displayed when viewing your site.'),
81
+ actions: canCreate ? [{
82
+ icon: addTemplate,
83
+ label: __('Add template'),
84
+ onClick: () => setIsCreateModalOpen(true)
85
+ }] : [],
86
+ onClose: onClose
87
+ }), isPostsPage ? createElement(Notice, {
88
+ className: "edit-post-post-template__notice",
89
+ status: "warning",
90
+ isDismissible: false
91
+ }, __('The posts page template cannot be changed.')) : createElement(SelectControl, {
92
+ hideLabelFromVision: true,
93
+ label: __('Template'),
94
+ value: (_selectedOption$value = selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.value) !== null && _selectedOption$value !== void 0 ? _selectedOption$value : '',
95
+ options: options,
96
+ onChange: slug => editPost({
97
+ template: slug || ''
98
+ })
99
+ }), canEdit && createElement("p", null, createElement(Button, {
100
+ variant: "link",
101
+ onClick: () => __unstableSwitchToTemplateMode()
102
+ }, __('Edit template'))), isCreateModalOpen && createElement(PostTemplateCreateModal, {
103
+ onClose: () => setIsCreateModalOpen(false)
104
+ }));
105
+ }
106
+ //# sourceMappingURL=form.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/edit-post/src/components/sidebar/post-template/form.js"],"names":["useState","useMemo","__experimentalInspectorPopoverHeader","InspectorPopoverHeader","__","addTemplate","Notice","SelectControl","Button","useSelect","useDispatch","store","editorStore","coreStore","editPostStore","PostTemplateCreateModal","PostTemplateForm","onClose","isPostsPage","availableTemplates","fetchedTemplates","selectedTemplateSlug","canCreate","canEdit","select","editorSettings","getEditorSettings","siteSettings","getEntityRecord","_isPostsPage","getCurrentPostId","page_for_posts","canCreateTemplates","canUser","getEntityRecords","post_type","getCurrentPostType","per_page","getEditedPostAttribute","supportsTemplateMode","getEditedPostTemplate","options","Object","entries","fromEntries","map","slug","title","rendered","value","label","selectedOption","find","option","editPost","__unstableSwitchToTemplateMode","isCreateModalOpen","setIsCreateModalOpen","icon","onClick","template"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,QAAT,EAAmBC,OAAnB,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,OAAO,EAAC,MADT;AAEC,IAAA,OAAO,EAAG,MAAMgC,8BAA8B;AAF/C,KAIGnD,EAAE,CAAE,eAAF,CAJL,CADD,CAvCF,EAgDGoD,iBAAiB,IAClB,cAAC,uBAAD;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,109 @@
1
+ import { createElement } from "@wordpress/element";
2
+
3
+ /**
4
+ * WordPress dependencies
5
+ */
6
+ import { useRef } from '@wordpress/element';
7
+ import { PanelRow, Dropdown, Button } from '@wordpress/components';
8
+ import { __, sprintf } from '@wordpress/i18n';
9
+ import { useSelect } from '@wordpress/data';
10
+ import { store as editorStore } from '@wordpress/editor';
11
+ import { store as coreStore } from '@wordpress/core-data';
12
+ /**
13
+ * Internal dependencies
14
+ */
15
+
16
+ import PostTemplateForm from './form';
17
+ export default function PostTemplate() {
18
+ const anchorRef = useRef();
19
+ const isVisible = useSelect(select => {
20
+ var _select$canUser;
21
+
22
+ const postTypeSlug = select(editorStore).getCurrentPostType();
23
+ const postType = select(coreStore).getPostType(postTypeSlug);
24
+
25
+ if (!(postType !== null && postType !== void 0 && postType.viewable)) {
26
+ return false;
27
+ }
28
+
29
+ const settings = select(editorStore).getEditorSettings();
30
+ const hasTemplates = !!settings.availableTemplates && Object.keys(settings.availableTemplates).length > 0;
31
+
32
+ if (hasTemplates) {
33
+ return true;
34
+ }
35
+
36
+ const canCreateTemplates = (_select$canUser = select(coreStore).canUser('create', 'templates')) !== null && _select$canUser !== void 0 ? _select$canUser : false;
37
+ return canCreateTemplates;
38
+ }, []);
39
+
40
+ if (!isVisible) {
41
+ return null;
42
+ }
43
+
44
+ return createElement(PanelRow, {
45
+ className: "edit-post-post-template",
46
+ ref: anchorRef
47
+ }, createElement("span", null, __('Template')), createElement(Dropdown, {
48
+ popoverProps: {
49
+ anchorRef
50
+ },
51
+ position: "bottom left",
52
+ className: "edit-post-post-template__dropdown",
53
+ contentClassName: "edit-post-post-template__dialog",
54
+ renderToggle: _ref => {
55
+ let {
56
+ isOpen,
57
+ onToggle
58
+ } = _ref;
59
+ return createElement(PostTemplateToggle, {
60
+ isOpen: isOpen,
61
+ onClick: onToggle
62
+ });
63
+ },
64
+ renderContent: _ref2 => {
65
+ let {
66
+ onClose
67
+ } = _ref2;
68
+ return createElement(PostTemplateForm, {
69
+ onClose: onClose
70
+ });
71
+ }
72
+ }));
73
+ }
74
+
75
+ function PostTemplateToggle(_ref3) {
76
+ let {
77
+ isOpen,
78
+ onClick
79
+ } = _ref3;
80
+ const templateTitle = useSelect(select => {
81
+ var _select$getEntityReco;
82
+
83
+ const templateSlug = select(editorStore).getEditedPostAttribute('template');
84
+ const settings = select(editorStore).getEditorSettings();
85
+
86
+ if (settings.availableTemplates[templateSlug]) {
87
+ return settings.availableTemplates[templateSlug];
88
+ }
89
+
90
+ const template = (_select$getEntityReco = select(coreStore).getEntityRecords('postType', 'wp_template', {
91
+ per_page: -1
92
+ })) === null || _select$getEntityReco === void 0 ? void 0 : _select$getEntityReco.find(_ref4 => {
93
+ let {
94
+ slug
95
+ } = _ref4;
96
+ return slug === templateSlug;
97
+ });
98
+ return template === null || template === void 0 ? void 0 : template.title.rendered;
99
+ }, []);
100
+ return createElement(Button, {
101
+ className: "edit-post-post-template__toggle",
102
+ variant: "tertiary",
103
+ "aria-expanded": isOpen,
104
+ "aria-label": templateTitle ? sprintf( // translators: %s: Name of the currently selected template.
105
+ __('Select template: %s'), templateTitle) : __('Select template'),
106
+ onClick: onClick
107
+ }, templateTitle !== null && templateTitle !== void 0 ? templateTitle : __('(none)'));
108
+ }
109
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/edit-post/src/components/sidebar/post-template/index.js"],"names":["useRef","PanelRow","Dropdown","Button","__","sprintf","useSelect","store","editorStore","coreStore","PostTemplateForm","PostTemplate","anchorRef","isVisible","select","postTypeSlug","getCurrentPostType","postType","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":";;AAAA;AACA;AACA;AACA,SAASA,MAAT,QAAuB,oBAAvB;AACA,SAASC,QAAT,EAAmBC,QAAnB,EAA6BC,MAA7B,QAA2C,uBAA3C;AACA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SAASC,KAAK,IAAIC,WAAlB,QAAqC,mBAArC;AACA,SAASD,KAAK,IAAIE,SAAlB,QAAmC,sBAAnC;AAEA;AACA;AACA;;AACA,OAAOC,gBAAP,MAA6B,QAA7B;AAEA,eAAe,SAASC,YAAT,GAAwB;AACtC,QAAMC,SAAS,GAAGZ,MAAM,EAAxB;AAEA,QAAMa,SAAS,GAAGP,SAAS,CAAI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,EAAE,CAAE,iBAAF,CAXP;AAaC,IAAA,OAAO,EAAG6B;AAbX,KAeGC,aAfH,aAeGA,aAfH,cAeGA,aAfH,GAeoB9B,EAAE,CAAE,QAAF,CAftB,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"]}
@@ -24,7 +24,6 @@ import PageAttributes from '../page-attributes';
24
24
  import MetaBoxes from '../../meta-boxes';
25
25
  import PluginDocumentSettingPanel from '../plugin-document-setting-panel';
26
26
  import PluginSidebarEditPost from '../plugin-sidebar';
27
- import Template from '../template';
28
27
  import TemplateSummary from '../template-summary';
29
28
  import { __ } from '@wordpress/i18n';
30
29
  import { useSelect } from '@wordpress/data';
@@ -77,7 +76,7 @@ const SettingsSidebar = () => {
77
76
  toggleShortcut: keyboardShortcut,
78
77
  icon: cog,
79
78
  isActiveByDefault: SIDEBAR_ACTIVE_BY_DEFAULT
80
- }, !isTemplateMode && sidebarName === 'edit-post/document' && createElement(Fragment, null, createElement(PostStatus, null), createElement(Template, null), createElement(PluginDocumentSettingPanel.Slot, null), createElement(LastRevision, null), createElement(PostLink, null), createElement(PostTaxonomies, null), createElement(FeaturedImage, null), createElement(PostExcerpt, null), createElement(DiscussionPanel, null), createElement(PageAttributes, null), createElement(MetaBoxes, {
79
+ }, !isTemplateMode && sidebarName === 'edit-post/document' && createElement(Fragment, null, createElement(PostStatus, null), createElement(PluginDocumentSettingPanel.Slot, null), createElement(LastRevision, null), createElement(PostLink, null), createElement(PostTaxonomies, null), createElement(FeaturedImage, null), createElement(PostExcerpt, null), createElement(DiscussionPanel, null), createElement(PageAttributes, null), createElement(MetaBoxes, {
81
80
  location: "side"
82
81
  })), isTemplateMode && sidebarName === 'edit-post/document' && createElement(TemplateSummary, null), sidebarName === 'edit-post/block' && createElement(BlockInspector, null));
83
82
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-post/src/components/sidebar/settings-sidebar/index.js"],"names":["BlockInspector","store","blockEditorStore","cog","Platform","keyboardShortcutsStore","interfaceStore","SettingsHeader","PostStatus","LastRevision","PostTaxonomies","FeaturedImage","PostExcerpt","PostLink","DiscussionPanel","PageAttributes","MetaBoxes","PluginDocumentSettingPanel","PluginSidebarEditPost","Template","TemplateSummary","__","useSelect","editPostStore","SIDEBAR_ACTIVE_BY_DEFAULT","select","web","native","SettingsSidebar","sidebarName","keyboardShortcut","isTemplateMode","sidebar","getActiveComplementaryArea","name","includes","getBlockSelectionStart","shortcut","getShortcutRepresentation","isEditingTemplate"],"mappings":";;AAAA;AACA;AACA;AACA,SACCA,cADD,EAECC,KAAK,IAAIC,gBAFV,QAGO,yBAHP;AAIA,SAASC,GAAT,QAAoB,kBAApB;AACA,SAASC,QAAT,QAAyB,oBAAzB;AACA,SAASH,KAAK,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OA7BxC,CADD;AAiCA,CApED;;AAsEA,eAAeD,eAAf","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":["BlockInspector","store","blockEditorStore","cog","Platform","keyboardShortcutsStore","interfaceStore","SettingsHeader","PostStatus","LastRevision","PostTaxonomies","FeaturedImage","PostExcerpt","PostLink","DiscussionPanel","PageAttributes","MetaBoxes","PluginDocumentSettingPanel","PluginSidebarEditPost","TemplateSummary","__","useSelect","editPostStore","SIDEBAR_ACTIVE_BY_DEFAULT","select","web","native","SettingsSidebar","sidebarName","keyboardShortcut","isTemplateMode","sidebar","getActiveComplementaryArea","name","includes","getBlockSelectionStart","shortcut","getShortcutRepresentation","isEditingTemplate"],"mappings":";;AAAA;AACA;AACA;AACA,SACCA,cADD,EAECC,KAAK,IAAIC,gBAFV,QAGO,yBAHP;AAIA,SAASC,GAAT,QAAoB,kBAApB;AACA,SAASC,QAAT,QAAyB,oBAAzB;AACA,SAASH,KAAK,IAAII,sBAAlB,QAAgD,+BAAhD;AACA,SAASJ,KAAK,IAAIK,cAAlB,QAAwC,sBAAxC;AAEA;AACA;AACA;;AACA,OAAOC,cAAP,MAA2B,oBAA3B;AACA,OAAOC,UAAP,MAAuB,gBAAvB;AACA,OAAOC,YAAP,MAAyB,kBAAzB;AACA,OAAOC,cAAP,MAA2B,oBAA3B;AACA,OAAOC,aAAP,MAA0B,mBAA1B;AACA,OAAOC,WAAP,MAAwB,iBAAxB;AACA,OAAOC,QAAP,MAAqB,cAArB;AACA,OAAOC,eAAP,MAA4B,qBAA5B;AACA,OAAOC,cAAP,MAA2B,oBAA3B;AACA,OAAOC,SAAP,MAAsB,kBAAtB;AACA,OAAOC,0BAAP,MAAuC,kCAAvC;AACA,OAAOC,qBAAP,MAAkC,mBAAlC;AACA,OAAOC,e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R,EAAE,CAAE,gBAAF,CAHhB;AAIC,IAAA,eAAe,EAAC;AAChB;AALD;AAMC,IAAA,KAAK,EAAGA,EAAE,CAAE,UAAF,CANX;AAOC,IAAA,cAAc,EAAGS,gBAPlB;AAQC,IAAA,IAAI,EAAG1B,GARR;AASC,IAAA,iBAAiB,EAAGoB;AATrB,KAWG,CAAEO,cAAF,IAAoBF,WAAW,KAAK,oBAApC,IACD,8BACC,cAAC,UAAD,OADD,EAEC,cAAC,0BAAD,CAA4B,IAA5B,OAFD,EAGC,cAAC,YAAD,OAHD,EAIC,cAAC,QAAD,OAJD,EAKC,cAAC,cAAD,OALD,EAMC,cAAC,aAAD,OAND,EAOC,cAAC,WAAD,OAPD,EAQC,cAAC,eAAD,OARD,EASC,cAAC,cAAD,OATD,EAUC,cAAC,SAAD;AAAW,IAAA,QAAQ,EAAC;AAApB,IAVD,CAZF,EAyBGE,cAAc,IAAIF,WAAW,KAAK,oBAAlC,IACD,cAAC,eAAD,OA1BF,EA4BGA,WAAW,KAAK,iBAAhB,IAAqC,cAAC,cAAD,OA5BxC,CADD;AAgCA,CAnED;;AAqEA,eAAeD,eAAf","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"]}
@@ -5,7 +5,7 @@ import { createElement } from "@wordpress/element";
5
5
  */
6
6
  import { Modal } from '@wordpress/components';
7
7
  import { __ } from '@wordpress/i18n';
8
- import { useState, useEffect } from '@wordpress/element';
8
+ import { useState, useEffect, useMemo } from '@wordpress/element';
9
9
  import { store as blockEditorStore, __experimentalBlockPatternsList as BlockPatternsList } from '@wordpress/block-editor';
10
10
  import { useSelect, useDispatch } from '@wordpress/data';
11
11
  import { useAsyncList } from '@wordpress/compose';
@@ -16,20 +16,40 @@ import { store as editorStore } from '@wordpress/editor';
16
16
 
17
17
  import { store as editPostStore } from '../../store';
18
18
 
19
- function PatternSelection(_ref) {
20
- let {
21
- onChoosePattern
22
- } = _ref;
19
+ function useStartPatterns() {
20
+ // A pattern is a start pattern if it includes 'core/post-content' in its blockTypes,
21
+ // and it has no postTypes declares and the current post type is page or if
22
+ // the current post type is part of the postTypes declared.
23
23
  const {
24
- blockPatterns
24
+ blockPatternsWithPostContentBlockType,
25
+ postType
25
26
  } = useSelect(select => {
26
27
  const {
27
28
  __experimentalGetPatternsByBlockTypes
28
29
  } = select(blockEditorStore);
30
+ const {
31
+ getCurrentPostType
32
+ } = select(editorStore);
29
33
  return {
30
- blockPatterns: __experimentalGetPatternsByBlockTypes('core/post-content')
34
+ // get pa
35
+ blockPatternsWithPostContentBlockType: __experimentalGetPatternsByBlockTypes('core/post-content'),
36
+ postType: getCurrentPostType()
31
37
  };
32
38
  }, []);
39
+ return useMemo(() => {
40
+ // filter patterns without postTypes declared if the current postType is page
41
+ // or patterns that declare the current postType in its post type array.
42
+ return blockPatternsWithPostContentBlockType.filter(pattern => {
43
+ return postType === 'page' && !pattern.postTypes || Array.isArray(pattern.postTypes) && pattern.postTypes.includes(postType);
44
+ });
45
+ }, [postType, blockPatternsWithPostContentBlockType]);
46
+ }
47
+
48
+ function PatternSelection(_ref) {
49
+ let {
50
+ onChoosePattern
51
+ } = _ref;
52
+ const blockPatterns = useStartPatterns();
33
53
  const shownBlockPatterns = useAsyncList(blockPatterns);
34
54
  const {
35
55
  resetEditorBlocks
@@ -51,16 +71,14 @@ const START_PAGE_MODAL_STATES = {
51
71
  };
52
72
  export default function StartPageOptions() {
53
73
  const [modalState, setModalState] = useState(START_PAGE_MODAL_STATES.INITIAL);
74
+ const blockPatterns = useStartPatterns();
75
+ const hasStartPattern = blockPatterns.length > 0;
54
76
  const shouldOpenModel = useSelect(select => {
55
- if (modalState !== START_PAGE_MODAL_STATES.INITIAL) {
77
+ if (!hasStartPattern || modalState !== START_PAGE_MODAL_STATES.INITIAL) {
56
78
  return false;
57
79
  }
58
80
 
59
81
  const {
60
- __experimentalGetPatternsByBlockTypes
61
- } = select(blockEditorStore);
62
- const {
63
- getCurrentPostType,
64
82
  getEditedPostContent,
65
83
  isEditedPostSaveable
66
84
  } = select(editorStore);
@@ -68,8 +86,8 @@ export default function StartPageOptions() {
68
86
  isEditingTemplate,
69
87
  isFeatureActive
70
88
  } = select(editPostStore);
71
- return getCurrentPostType() === 'page' && !isEditedPostSaveable() && '' === getEditedPostContent() && !isEditingTemplate() && !isFeatureActive('welcomeGuide') && __experimentalGetPatternsByBlockTypes('core/post-content').length >= 1;
72
- }, [modalState]);
89
+ return !isEditedPostSaveable() && '' === getEditedPostContent() && !isEditingTemplate() && !isFeatureActive('welcomeGuide');
90
+ }, [modalState, hasStartPattern]);
73
91
  useEffect(() => {
74
92
  if (shouldOpenModel) {
75
93
  setModalState(START_PAGE_MODAL_STATES.PATTERN);
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-post/src/components/start-page-options/index.js"],"names":["Modal","__","useState","useEffect","store","blockEditorStore","__experimentalBlockPatternsList","BlockPatternsList","useSelect","useDispatch","useAsyncList","editorStore","editPostStore","PatternSelection","onChoosePattern","blockPatterns","select","__experimentalGetPatternsByBlockTypes","shownBlockPatterns","resetEditorBlocks","_pattern","blocks","START_PAGE_MODAL_STATES","INITIAL","PATTERN","CLOSED","StartPageOptions","modalState","setModalState","shouldOpenModel","getCurrentPostType","getEditedPostContent","isEditedPostSaveable","isEditingTemplate","isFeatureActive","length"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,KAAT,QAAsB,uBAAtB;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,QAAT,EAAmBC,SAAnB,QAAoC,oBAApC;AACA,SACCC,KAAK,IAAIC,gBADV,EAECC,+BAA+B,IAAIC,iBAFpC,QAGO,yBAHP;AAIA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,YAAT,QAA6B,oBAA7B;AACA,SAASN,KAAK,IAAIO,WAAlB,QAAqC,mBAArC;AAEA;AACA;AACA;;AACA,SAASP,KAAK,IAAIQ,aAAlB,QAAuC,a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AAKA,UAAM;AAAEsB,MAAAA,iBAAF;AAAqBC,MAAAA;AAArB,QACLlB,MAAM,CAAEJ,aAAF,CADP;AAEA,WACCkB,kBAAkB,OAAO,MAAzB,IACA,CAAEE,oBAAoB,EADtB,IAEA,OAAOD,oBAAoB,EAF3B,IAGA,CAAEE,iBAAiB,EAHnB,IAIA,CAAEC,eAAe,CAAE,cAAF,CAJjB,IAKAjB,qCAAqC,CAAE,mBAAF,CAArC,CACEkB,MADF,IACY,CAPb;AASA,GAvB+B,EAwBhC,CAAER,UAAF,CAxBgC,CAAjC;AA2BAxB,EAAAA,SAAS,CAAE,MAAM;AAChB,QAAK0B,eAAL,EAAuB;AACtBD,MAAAA,aAAa,CAAEN,uBAAuB,CAACE,OAA1B,CAAb;AACA;AACD,GAJQ,EAIN,CAAEK,eAAF,CAJM,CAAT;;AAMA,MACCF,UAAU,KAAKL,uBAAuB,CAACC,OAAvC,IACAI,UAAU,KAAKL,uBAAuB,CAACG,MAFxC,EAGE;AACD,WAAO,IAAP;AACA;;AACD,SACC,cAAC,KAAD;AACC,IAAA,SAAS,EAAC,qCADX;AAEC,IAAA,KAAK,EAAGxB,EAAE,CAAE,kBAAF,CAFX;AAGC,IAAA,UAAU,EAAGA,EAAE,CAAE,QAAF,CAHhB;AAIC,IAAA,cAAc,EAAG,MAAM;AACtB2B,MAAAA,aAAa,CAAEN,uBAAuB,CAACG,MAA1B,CAAb;AACA;AANF,KAQC;AAAK,IAAA,SAAS,EAAC;AAAf,KACGE,UAAU,KAAKL,uBAAuB,CAACE,OAAvC,IACD,cAAC,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 } =\n\t\t\tselect( blockEditorStore );\n\t\treturn {\n\t\t\tblockPatterns:\n\t\t\t\t__experimentalGetPatternsByBlockTypes( 'core/post-content' ),\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 } =\n\t\t\t\tselect( blockEditorStore );\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 } =\n\t\t\t\tselect( editPostStore );\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":["Modal","__","useState","useEffect","useMemo","store","blockEditorStore","__experimentalBlockPatternsList","BlockPatternsList","useSelect","useDispatch","useAsyncList","editorStore","editPostStore","useStartPatterns","blockPatternsWithPostContentBlockType","postType","select","__experimentalGetPatternsByBlockTypes","getCurrentPostType","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"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,KAAT,QAAsB,uBAAtB;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,QAAT,EAAmBC,SAAnB,EAA8BC,OAA9B,QAA6C,oBAA7C;AACA,SACCC,KAAK,IAAIC,gBADV,EAECC,+BAA+B,IAAIC,iBAFpC,QAGO,yBAHP;AAIA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,YAAT,QAA6B,oBAA7B;AACA,SAASN,KAAK,IAAIO,WAAlB,QAAqC,mBAArC;AAEA;AACA;AACA;;AACA,SAASP,KAAK,IAAIQ,aAAlB,QAAuC,aAAvC;;AAEA,SAASC,gBAAT,GAA4B;AAC3B;AACA;AACA;AACA,QAAM;AAAEC,IAAAA,qCAAF;AAAyCC,IAAAA;AAAzC,MAAsDP,SAAS,CAClEQ,MAAF,IAAc;AACb,UAAM;AAAEC,MAAAA;AAAF,QACLD,MAAM,CAAEX,gBAAF,CADP;AAEA,UAAM;AAAEa,MAAAA;AAAF,QAAyBF,MAAM,CAAEL,WAAF,CAArC;AACA,WAAO;AACN;AACAG,MAAAA,qCAAqC,EACpCG,qCAAqC,CACpC,mBADoC,CAHhC;AAMNF,MAAAA,QAAQ,EAAEG,kBAAkB;AANtB,KAAP;AAQA,GAbmE,EAcpE,EAdoE,CAArE;AAiBA,SAAOf,OAAO,CAAE,MAAM;AACrB;AACA;AACA,WAAOW,qCAAqC,CAACK,MAAtC,CAAgDC,OAAF,IAAe;AACnE,aACGL,QAAQ,KAAK,MAAb,IAAuB,CAAEK,OAAO,CAACC,SAAnC,IACEC,KAAK,CAACC,OAAN,CAAeH,OAAO,CAACC,SAAvB,KACDD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AAF;AAAqBC,MAAAA;AAArB,QACL7B,MAAM,CAAEJ,aAAF,CADP;AAEA,WACC,CAAE+B,oBAAoB,EAAtB,IACA,OAAOD,oBAAoB,EAD3B,IAEA,CAAEE,iBAAiB,EAFnB,IAGA,CAAEC,eAAe,CAAE,cAAF,CAJlB;AAMA,GAlB+B,EAmBhC,CAAER,UAAF,EAAcE,eAAd,CAnBgC,CAAjC;AAsBArC,EAAAA,SAAS,CAAE,MAAM;AAChB,QAAKuC,eAAL,EAAuB;AACtBH,MAAAA,aAAa,CAAEN,uBAAuB,CAACE,OAA1B,CAAb;AACA;AACD,GAJQ,EAIN,CAAEO,eAAF,CAJM,CAAT;;AAMA,MACCJ,UAAU,KAAKL,uBAAuB,CAACC,OAAvC,IACAI,UAAU,KAAKL,uBAAuB,CAACG,MAFxC,EAGE;AACD,WAAO,IAAP;AACA;;AACD,SACC,cAAC,KAAD;AACC,IAAA,SAAS,EAAC,qCADX;AAEC,IAAA,KAAK,EAAGnC,EAAE,CAAE,kBAAF,CAFX;AAGC,IAAA,UAAU,EAAGA,EAAE,CAAE,QAAF,CAHhB;AAIC,IAAA,cAAc,EAAG,MAAM;AACtBsC,MAAAA,aAAa,CAAEN,uBAAuB,CAACG,MAA1B,CAAb;AACA;AANF,KAQC;AAAK,IAAA,SAAS,EAAC;AAAf,KACGE,UAAU,KAAKL,uBAAuB,CAACE,OAAvC,IACD,cAAC,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"]}
@@ -4,7 +4,7 @@ import { createElement } from "@wordpress/element";
4
4
  /**
5
5
  * External dependencies
6
6
  */
7
- import { forEach, size, map, without } from 'lodash';
7
+ import { forEach, map, without } from 'lodash';
8
8
  /**
9
9
  * WordPress dependencies
10
10
  */
@@ -118,7 +118,7 @@ function Editor(_ref) {
118
118
  defaultAllowedBlockTypes: settings.allowedBlockTypes
119
119
  }; // Omit hidden block types if exists and non-empty.
120
120
 
121
- if (size(hiddenBlockTypes) > 0) {
121
+ if (hiddenBlockTypes.length > 0) {
122
122
  // Defer to passed setting for `allowedBlockTypes` if provided as
123
123
  // anything other than `true` (where `true` is equivalent to allow
124
124
  // all block types).