@wordpress/edit-post 7.24.0 → 7.25.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 (143) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/header/header-toolbar/index.js +8 -4
  3. package/build/components/header/header-toolbar/index.js.map +1 -1
  4. package/build/components/header/index.js +13 -11
  5. package/build/components/header/index.js.map +1 -1
  6. package/build/components/header/mode-switcher/index.js +1 -1
  7. package/build/components/header/mode-switcher/index.js.map +1 -1
  8. package/build/components/header/more-menu/index.js +2 -1
  9. package/build/components/header/more-menu/index.js.map +1 -1
  10. package/build/components/header/writing-menu/index.js +13 -12
  11. package/build/components/header/writing-menu/index.js.map +1 -1
  12. package/build/components/layout/index.js +12 -12
  13. package/build/components/layout/index.js.map +1 -1
  14. package/build/components/preferences-modal/index.js +65 -49
  15. package/build/components/preferences-modal/index.js.map +1 -1
  16. package/build/components/sidebar/post-status/index.js +1 -2
  17. package/build/components/sidebar/post-status/index.js.map +1 -1
  18. package/build/components/sidebar/settings-header/index.js +17 -43
  19. package/build/components/sidebar/settings-header/index.js.map +1 -1
  20. package/build/components/sidebar/settings-sidebar/index.js +80 -20
  21. package/build/components/sidebar/settings-sidebar/index.js.map +1 -1
  22. package/build/components/start-page-options/index.js +3 -3
  23. package/build/components/start-page-options/index.js.map +1 -1
  24. package/build/components/visual-editor/index.js +20 -257
  25. package/build/components/visual-editor/index.js.map +1 -1
  26. package/build/components/welcome-guide/index.js +6 -3
  27. package/build/components/welcome-guide/index.js.map +1 -1
  28. package/build/editor.js +5 -6
  29. package/build/editor.js.map +1 -1
  30. package/build/editor.native.js +1 -2
  31. package/build/editor.native.js.map +1 -1
  32. package/build/index.js +5 -4
  33. package/build/index.js.map +1 -1
  34. package/build/plugins/welcome-guide-menu-item/index.js +2 -6
  35. package/build/plugins/welcome-guide-menu-item/index.js.map +1 -1
  36. package/build/store/actions.js +35 -39
  37. package/build/store/actions.js.map +1 -1
  38. package/build/store/reducer.js +1 -34
  39. package/build/store/reducer.js.map +1 -1
  40. package/build/store/selectors.js +22 -12
  41. package/build/store/selectors.js.map +1 -1
  42. package/build-module/components/header/header-toolbar/index.js +8 -4
  43. package/build-module/components/header/header-toolbar/index.js.map +1 -1
  44. package/build-module/components/header/index.js +15 -13
  45. package/build-module/components/header/index.js.map +1 -1
  46. package/build-module/components/header/mode-switcher/index.js +1 -1
  47. package/build-module/components/header/mode-switcher/index.js.map +1 -1
  48. package/build-module/components/header/more-menu/index.js +2 -1
  49. package/build-module/components/header/more-menu/index.js.map +1 -1
  50. package/build-module/components/header/writing-menu/index.js +14 -13
  51. package/build-module/components/header/writing-menu/index.js.map +1 -1
  52. package/build-module/components/layout/index.js +13 -13
  53. package/build-module/components/layout/index.js.map +1 -1
  54. package/build-module/components/preferences-modal/index.js +65 -49
  55. package/build-module/components/preferences-modal/index.js.map +1 -1
  56. package/build-module/components/sidebar/post-status/index.js +2 -3
  57. package/build-module/components/sidebar/post-status/index.js.map +1 -1
  58. package/build-module/components/sidebar/settings-header/index.js +20 -46
  59. package/build-module/components/sidebar/settings-header/index.js.map +1 -1
  60. package/build-module/components/sidebar/settings-sidebar/index.js +80 -21
  61. package/build-module/components/sidebar/settings-sidebar/index.js.map +1 -1
  62. package/build-module/components/start-page-options/index.js +3 -3
  63. package/build-module/components/start-page-options/index.js.map +1 -1
  64. package/build-module/components/visual-editor/index.js +24 -261
  65. package/build-module/components/visual-editor/index.js.map +1 -1
  66. package/build-module/components/welcome-guide/index.js +6 -3
  67. package/build-module/components/welcome-guide/index.js.map +1 -1
  68. package/build-module/editor.js +5 -6
  69. package/build-module/editor.js.map +1 -1
  70. package/build-module/editor.native.js +1 -2
  71. package/build-module/editor.native.js.map +1 -1
  72. package/build-module/index.js +3 -2
  73. package/build-module/index.js.map +1 -1
  74. package/build-module/plugins/welcome-guide-menu-item/index.js +2 -6
  75. package/build-module/plugins/welcome-guide-menu-item/index.js.map +1 -1
  76. package/build-module/store/actions.js +31 -36
  77. package/build-module/store/actions.js.map +1 -1
  78. package/build-module/store/reducer.js +1 -33
  79. package/build-module/store/reducer.js.map +1 -1
  80. package/build-module/store/selectors.js +18 -9
  81. package/build-module/store/selectors.js.map +1 -1
  82. package/build-style/style-rtl.css +63 -200
  83. package/build-style/style.css +63 -200
  84. package/package.json +32 -32
  85. package/src/components/header/header-toolbar/index.js +4 -0
  86. package/src/components/header/header-toolbar/style.scss +15 -13
  87. package/src/components/header/index.js +28 -13
  88. package/src/components/header/mode-switcher/index.js +2 -1
  89. package/src/components/header/more-menu/index.js +1 -0
  90. package/src/components/header/style.scss +60 -34
  91. package/src/components/header/writing-menu/index.js +16 -18
  92. package/src/components/keyboard-shortcut-help-modal/test/__snapshots__/index.js.snap +1 -1
  93. package/src/components/layout/index.js +13 -12
  94. package/src/components/preferences-modal/index.js +109 -96
  95. package/src/components/preferences-modal/test/index.js +1 -52
  96. package/src/components/sidebar/post-status/index.js +2 -2
  97. package/src/components/sidebar/settings-header/index.js +19 -71
  98. package/src/components/sidebar/settings-sidebar/index.js +117 -54
  99. package/src/components/sidebar/style.scss +4 -12
  100. package/src/components/start-page-options/index.js +3 -3
  101. package/src/components/visual-editor/index.js +26 -359
  102. package/src/components/visual-editor/style.scss +0 -15
  103. package/src/components/welcome-guide/index.js +4 -2
  104. package/src/editor.js +7 -7
  105. package/src/editor.native.js +3 -9
  106. package/src/index.js +3 -2
  107. package/src/plugins/welcome-guide-menu-item/index.js +3 -6
  108. package/src/store/actions.js +32 -46
  109. package/src/store/reducer.js +0 -33
  110. package/src/store/selectors.js +23 -9
  111. package/src/store/test/actions.js +0 -28
  112. package/src/style.scss +0 -3
  113. package/src/test/__snapshots__/editor.native.js.snap +21 -0
  114. package/src/test/editor.native.js +90 -56
  115. package/build/components/device-preview/index.js +0 -72
  116. package/build/components/device-preview/index.js.map +0 -1
  117. package/build/components/header/document-actions/index.js +0 -82
  118. package/build/components/header/document-actions/index.js.map +0 -1
  119. package/build/components/sidebar/post-template/create-modal.js +0 -99
  120. package/build/components/sidebar/post-template/create-modal.js.map +0 -1
  121. package/build/components/sidebar/post-template/form.js +0 -110
  122. package/build/components/sidebar/post-template/form.js.map +0 -1
  123. package/build/components/sidebar/post-template/index.js +0 -106
  124. package/build/components/sidebar/post-template/index.js.map +0 -1
  125. package/build-module/components/device-preview/index.js +0 -65
  126. package/build-module/components/device-preview/index.js.map +0 -1
  127. package/build-module/components/header/document-actions/index.js +0 -74
  128. package/build-module/components/header/document-actions/index.js.map +0 -1
  129. package/build-module/components/sidebar/post-template/create-modal.js +0 -92
  130. package/build-module/components/sidebar/post-template/create-modal.js.map +0 -1
  131. package/build-module/components/sidebar/post-template/form.js +0 -102
  132. package/build-module/components/sidebar/post-template/form.js.map +0 -1
  133. package/build-module/components/sidebar/post-template/index.js +0 -98
  134. package/build-module/components/sidebar/post-template/index.js.map +0 -1
  135. package/src/components/device-preview/index.js +0 -73
  136. package/src/components/header/document-actions/index.js +0 -82
  137. package/src/components/header/document-actions/style.scss +0 -64
  138. package/src/components/sidebar/post-template/create-modal.js +0 -140
  139. package/src/components/sidebar/post-template/form.js +0 -141
  140. package/src/components/sidebar/post-template/index.js +0 -120
  141. package/src/components/sidebar/post-template/style.scss +0 -22
  142. package/src/components/sidebar/settings-header/style.scss +0 -74
  143. package/src/components/sidebar/template/style.scss +0 -35
@@ -1 +0,0 @@
1
- {"version":3,"names":["useSelect","useDispatch","store","editorStore","useState","serialize","createBlock","Modal","TextControl","Button","__experimentalHStack","HStack","__experimentalVStack","VStack","__","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","createElement","onRequestClose","className","onSubmit","spacing","__nextHasNoMarginBottom","label","value","onChange","placeholder","disabled","help","justify","variant","onClick","type"],"sources":["@wordpress/edit-post/src/components/sidebar/post-template/create-modal.js"],"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\tTextControl,\n\tButton,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\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\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<VStack spacing=\"3\">\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\tplaceholder={ DEFAULT_TITLE }\n\t\t\t\t\t\tdisabled={ isBusy }\n\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t'Describe the template, e.g. \"Post with sidebar\". A custom template can be manually applied to any post or page.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t/>\n\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t<Button variant=\"tertiary\" onClick={ cancel }>\n\t\t\t\t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CAAC;EAED,OACCe,aAAA,CAAChC,KAAK;IACLkB,KAAK,EAAGX,EAAE,CAAE,wBAAyB,CAAG;IACxC0B,cAAc,EAAGX,MAAQ;IACzBY,SAAS,EAAC;EAAuC,GAEjDF,aAAA;IACCE,SAAS,EAAC,sCAAsC;IAChDC,QAAQ,EAAGZ;EAAQ,GAEnBS,aAAA,CAAC1B,MAAM;IAAC8B,OAAO,EAAC;EAAG,GAClBJ,aAAA,CAAC/B,WAAW;IACXoC,uBAAuB;IACvBC,KAAK,EAAG/B,EAAE,CAAE,MAAO,CAAG;IACtBgC,KAAK,EAAGrB,KAAO;IACfsB,QAAQ,EAAGrB,QAAU;IACrBsB,WAAW,EAAG/B,aAAe;IAC7BgC,QAAQ,EAAGtB,MAAQ;IACnBuB,IAAI,EAAGpC,EAAE,CACR,iHACD;EAAG,CACH,CAAC,EACFyB,aAAA,CAAC5B,MAAM;IAACwC,OAAO,EAAC;EAAO,GACtBZ,aAAA,CAAC9B,MAAM;IAAC2C,OAAO,EAAC,UAAU;IAACC,OAAO,EAAGxB;EAAQ,GAC1Cf,EAAE,CAAE,QAAS,CACR,CAAC,EAETyB,aAAA,CAAC9B,MAAM;IACN2C,OAAO,EAAC,SAAS;IACjBE,IAAI,EAAC,QAAQ;IACb3B,MAAM,EAAGA,MAAQ;IACjB,iBAAgBA;EAAQ,GAEtBb,EAAE,CAAE,QAAS,CACR,CACD,CACD,CACH,CACA,CAAC;AAEV"}
@@ -1,102 +0,0 @@
1
- import { createElement } from "react";
2
- /**
3
- * WordPress dependencies
4
- */
5
- import { useState, useMemo } from '@wordpress/element';
6
- import { __experimentalInspectorPopoverHeader as InspectorPopoverHeader } from '@wordpress/block-editor';
7
- import { __ } from '@wordpress/i18n';
8
- import { addTemplate } from '@wordpress/icons';
9
- import { Notice, SelectControl, Button } from '@wordpress/components';
10
- import { useSelect, useDispatch } from '@wordpress/data';
11
- import { store as editorStore } from '@wordpress/editor';
12
- import { store as coreStore } from '@wordpress/core-data';
13
-
14
- /**
15
- * Internal dependencies
16
- */
17
- import { store as editPostStore } from '../../../store';
18
- import PostTemplateCreateModal from './create-modal';
19
- export default function PostTemplateForm({
20
- onClose
21
- }) {
22
- var _options$find, _selectedOption$value;
23
- const {
24
- isPostsPage,
25
- availableTemplates,
26
- fetchedTemplates,
27
- selectedTemplateSlug,
28
- canCreate,
29
- canEdit
30
- } = useSelect(select => {
31
- const {
32
- canUser,
33
- getEntityRecord,
34
- getEntityRecords
35
- } = select(coreStore);
36
- const editorSettings = select(editorStore).getEditorSettings();
37
- const siteSettings = canUser('read', 'settings') ? getEntityRecord('root', 'site') : undefined;
38
- const _isPostsPage = select(editorStore).getCurrentPostId() === siteSettings?.page_for_posts;
39
- const canCreateTemplates = canUser('create', 'templates');
40
- return {
41
- isPostsPage: _isPostsPage,
42
- availableTemplates: editorSettings.availableTemplates,
43
- fetchedTemplates: canCreateTemplates ? getEntityRecords('postType', 'wp_template', {
44
- post_type: select(editorStore).getCurrentPostType(),
45
- per_page: -1
46
- }) : undefined,
47
- selectedTemplateSlug: select(editorStore).getEditedPostAttribute('template'),
48
- canCreate: canCreateTemplates && !_isPostsPage && editorSettings.supportsTemplateMode,
49
- canEdit: canCreateTemplates && editorSettings.supportsTemplateMode && !!select(editPostStore).getEditedPostTemplate()
50
- };
51
- }, []);
52
- const options = useMemo(() => Object.entries({
53
- ...availableTemplates,
54
- ...Object.fromEntries((fetchedTemplates !== null && fetchedTemplates !== void 0 ? fetchedTemplates : []).map(({
55
- slug,
56
- title
57
- }) => [slug, title.rendered]))
58
- }).map(([slug, title]) => ({
59
- value: slug,
60
- label: title
61
- })), [availableTemplates, fetchedTemplates]);
62
- 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.
63
-
64
- const {
65
- editPost
66
- } = useDispatch(editorStore);
67
- const {
68
- __unstableSwitchToTemplateMode
69
- } = useDispatch(editPostStore);
70
- const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
71
- return createElement("div", {
72
- className: "edit-post-post-template__form"
73
- }, createElement(InspectorPopoverHeader, {
74
- title: __('Template'),
75
- help: __('Templates define the way content is displayed when viewing your site.'),
76
- actions: canCreate ? [{
77
- icon: addTemplate,
78
- label: __('Add template'),
79
- onClick: () => setIsCreateModalOpen(true)
80
- }] : [],
81
- onClose: onClose
82
- }), isPostsPage ? createElement(Notice, {
83
- className: "edit-post-post-template__notice",
84
- status: "warning",
85
- isDismissible: false
86
- }, __('The posts page template cannot be changed.')) : createElement(SelectControl, {
87
- __nextHasNoMarginBottom: true,
88
- hideLabelFromVision: true,
89
- label: __('Template'),
90
- value: (_selectedOption$value = selectedOption?.value) !== null && _selectedOption$value !== void 0 ? _selectedOption$value : '',
91
- options: options,
92
- onChange: slug => editPost({
93
- template: slug || ''
94
- })
95
- }), canEdit && createElement("p", null, createElement(Button, {
96
- variant: "link",
97
- onClick: () => __unstableSwitchToTemplateMode()
98
- }, __('Edit template'))), isCreateModalOpen && createElement(PostTemplateCreateModal, {
99
- onClose: () => setIsCreateModalOpen(false)
100
- }));
101
- }
102
- //# sourceMappingURL=form.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["useState","useMemo","__experimentalInspectorPopoverHeader","InspectorPopoverHeader","__","addTemplate","Notice","SelectControl","Button","useSelect","useDispatch","store","editorStore","coreStore","editPostStore","PostTemplateCreateModal","PostTemplateForm","onClose","_options$find","_selectedOption$value","isPostsPage","availableTemplates","fetchedTemplates","selectedTemplateSlug","canCreate","canEdit","select","canUser","getEntityRecord","getEntityRecords","editorSettings","getEditorSettings","siteSettings","undefined","_isPostsPage","getCurrentPostId","page_for_posts","canCreateTemplates","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","createElement","className","help","actions","icon","onClick","status","isDismissible","__nextHasNoMarginBottom","hideLabelFromVision","onChange","template","variant"],"sources":["@wordpress/edit-post/src/components/sidebar/post-template/form.js"],"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 { canUser, getEntityRecord, getEntityRecords } =\n\t\t\tselect( coreStore );\n\t\tconst editorSettings = select( editorStore ).getEditorSettings();\n\t\tconst siteSettings = canUser( 'read', 'settings' )\n\t\t\t? getEntityRecord( 'root', 'site' )\n\t\t\t: undefined;\n\t\tconst _isPostsPage =\n\t\t\tselect( editorStore ).getCurrentPostId() ===\n\t\t\tsiteSettings?.page_for_posts;\n\t\tconst canCreateTemplates = canUser( 'create', 'templates' );\n\n\t\treturn {\n\t\t\tisPostsPage: _isPostsPage,\n\t\t\tavailableTemplates: editorSettings.availableTemplates,\n\t\t\tfetchedTemplates: canCreateTemplates\n\t\t\t\t? getEntityRecords( 'postType', 'wp_template', {\n\t\t\t\t\t\tpost_type: select( editorStore ).getCurrentPostType(),\n\t\t\t\t\t\tper_page: -1,\n\t\t\t\t } )\n\t\t\t\t: undefined,\n\t\t\tselectedTemplateSlug:\n\t\t\t\tselect( editorStore ).getEditedPostAttribute( 'template' ),\n\t\t\tcanCreate:\n\t\t\t\tcanCreateTemplates &&\n\t\t\t\t! _isPostsPage &&\n\t\t\t\teditorSettings.supportsTemplateMode,\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\t__nextHasNoMarginBottom\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"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,QAAQ,EAAEC,OAAO,QAAQ,oBAAoB;AACtD,SAASC,oCAAoC,IAAIC,sBAAsB,QAAQ,yBAAyB;AACxG,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,WAAW,QAAQ,kBAAkB;AAC9C,SAASC,MAAM,EAAEC,aAAa,EAAEC,MAAM,QAAQ,uBAAuB;AACrE,SAASC,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACxD,SAASC,KAAK,IAAIC,WAAW,QAAQ,mBAAmB;AACxD,SAASD,KAAK,IAAIE,SAAS,QAAQ,sBAAsB;;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C,KAAK,EAAG9C,EAAE,CAAE,UAAW,CAAG;IAC1B2D,IAAI,EAAG3D,EAAE,CACR,uEACD,CAAG;IACH4D,OAAO,EACNxC,SAAS,GACN,CACA;MACCyC,IAAI,EAAE5D,WAAW;MACjBgD,KAAK,EAAEjD,EAAE,CAAE,cAAe,CAAC;MAC3B8D,OAAO,EAAEA,CAAA,KAAMN,oBAAoB,CAAE,IAAK;IAC3C,CAAC,CACA,GACD,EACH;IACD3C,OAAO,EAAGA;EAAS,CACnB,CAAC,EACAG,WAAW,GACZyC,aAAA,CAACvD,MAAM;IACNwD,SAAS,EAAC,iCAAiC;IAC3CK,MAAM,EAAC,SAAS;IAChBC,aAAa,EAAG;EAAO,GAErBhE,EAAE,CAAE,4CAA6C,CAC5C,CAAC,GAETyD,aAAA,CAACtD,aAAa;IACb8D,uBAAuB;IACvBC,mBAAmB;IACnBjB,KAAK,EAAGjD,EAAE,CAAE,UAAW,CAAG;IAC1BgD,KAAK,GAAAjC,qBAAA,GAAGmC,cAAc,EAAEF,KAAK,cAAAjC,qBAAA,cAAAA,qBAAA,GAAI,EAAI;IACrCyB,OAAO,EAAGA,OAAS;IACnB2B,QAAQ,EAAKtB,IAAI,IAChBQ,QAAQ,CAAE;MAAEe,QAAQ,EAAEvB,IAAI,IAAI;IAAG,CAAE;EACnC,CACD,CACD,EACCxB,OAAO,IACRoC,aAAA,YACCA,aAAA,CAACrD,MAAM;IACNiE,OAAO,EAAC,MAAM;IACdP,OAAO,EAAGA,CAAA,KAAMR,8BAA8B,CAAC;EAAG,GAEhDtD,EAAE,CAAE,eAAgB,CACf,CACN,CACH,EACCuD,iBAAiB,IAClBE,aAAA,CAAC9C,uBAAuB;IACvBE,OAAO,EAAGA,CAAA,KAAM2C,oBAAoB,CAAE,KAAM;EAAG,CAC/C,CAEE,CAAC;AAER"}
@@ -1,98 +0,0 @@
1
- import { createElement } from "react";
2
- /**
3
- * WordPress dependencies
4
- */
5
- import { useState, useMemo } from '@wordpress/element';
6
- import { Dropdown, Button } from '@wordpress/components';
7
- import { __, sprintf } from '@wordpress/i18n';
8
- import { useSelect } from '@wordpress/data';
9
- import { store as editorStore, privateApis as editorPrivateApis } from '@wordpress/editor';
10
- import { store as coreStore } from '@wordpress/core-data';
11
-
12
- /**
13
- * Internal dependencies
14
- */
15
- import PostTemplateForm from './form';
16
- import { store as editPostStore } from '../../../store';
17
- import { unlock } from '../../../lock-unlock';
18
- const {
19
- PostPanelRow
20
- } = unlock(editorPrivateApis);
21
- export default function PostTemplate() {
22
- // Use internal state instead of a ref to make sure that the component
23
- // re-renders when the popover's anchor updates.
24
- const [popoverAnchor, setPopoverAnchor] = useState(null);
25
- // Memoize popoverProps to avoid returning a new object every time.
26
- const popoverProps = useMemo(() => ({
27
- anchor: popoverAnchor,
28
- placement: 'bottom-end'
29
- }), [popoverAnchor]);
30
- const isVisible = useSelect(select => {
31
- var _select$canUser;
32
- const postTypeSlug = select(editorStore).getCurrentPostType();
33
- const postType = select(coreStore).getPostType(postTypeSlug);
34
- if (!postType?.viewable) {
35
- return false;
36
- }
37
- const settings = select(editorStore).getEditorSettings();
38
- const hasTemplates = !!settings.availableTemplates && Object.keys(settings.availableTemplates).length > 0;
39
- if (hasTemplates) {
40
- return true;
41
- }
42
- if (!settings.supportsTemplateMode) {
43
- return false;
44
- }
45
- const canCreateTemplates = (_select$canUser = select(coreStore).canUser('create', 'templates')) !== null && _select$canUser !== void 0 ? _select$canUser : false;
46
- return canCreateTemplates;
47
- }, []);
48
- if (!isVisible) {
49
- return null;
50
- }
51
- return createElement(PostPanelRow, {
52
- label: __('Template'),
53
- ref: setPopoverAnchor
54
- }, createElement(Dropdown, {
55
- popoverProps: popoverProps,
56
- contentClassName: "edit-post-post-template__dialog",
57
- focusOnMount: true,
58
- renderToggle: ({
59
- isOpen,
60
- onToggle
61
- }) => createElement(PostTemplateToggle, {
62
- isOpen: isOpen,
63
- onClick: onToggle
64
- }),
65
- renderContent: ({
66
- onClose
67
- }) => createElement(PostTemplateForm, {
68
- onClose: onClose
69
- })
70
- }));
71
- }
72
- function PostTemplateToggle({
73
- isOpen,
74
- onClick
75
- }) {
76
- const templateTitle = useSelect(select => {
77
- const templateSlug = select(editorStore).getEditedPostAttribute('template');
78
- const {
79
- supportsTemplateMode,
80
- availableTemplates
81
- } = select(editorStore).getEditorSettings();
82
- if (!supportsTemplateMode && availableTemplates[templateSlug]) {
83
- return availableTemplates[templateSlug];
84
- }
85
- const template = select(coreStore).canUser('create', 'templates') && select(editPostStore).getEditedPostTemplate();
86
- return template?.title || template?.slug || availableTemplates?.[templateSlug];
87
- }, []);
88
- return createElement(Button, {
89
- className: "edit-post-post-template__toggle",
90
- variant: "tertiary",
91
- "aria-expanded": isOpen,
92
- "aria-label": templateTitle ? sprintf(
93
- // translators: %s: Name of the currently selected template.
94
- __('Select template: %s'), templateTitle) : __('Select template'),
95
- onClick: onClick
96
- }, templateTitle !== null && templateTitle !== void 0 ? templateTitle : __('Default template'));
97
- }
98
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["useState","useMemo","Dropdown","Button","__","sprintf","useSelect","store","editorStore","privateApis","editorPrivateApis","coreStore","PostTemplateForm","editPostStore","unlock","PostPanelRow","PostTemplate","popoverAnchor","setPopoverAnchor","popoverProps","anchor","placement","isVisible","select","_select$canUser","postTypeSlug","getCurrentPostType","postType","getPostType","viewable","settings","getEditorSettings","hasTemplates","availableTemplates","Object","keys","length","supportsTemplateMode","canCreateTemplates","canUser","createElement","label","ref","contentClassName","focusOnMount","renderToggle","isOpen","onToggle","PostTemplateToggle","onClick","renderContent","onClose","templateTitle","templateSlug","getEditedPostAttribute","template","getEditedPostTemplate","title","slug","className","variant"],"sources":["@wordpress/edit-post/src/components/sidebar/post-template/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useMemo } from '@wordpress/element';\nimport { Dropdown, Button } from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useSelect } from '@wordpress/data';\nimport {\n\tstore as editorStore,\n\tprivateApis as editorPrivateApis,\n} from '@wordpress/editor';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport PostTemplateForm from './form';\nimport { store as editPostStore } from '../../../store';\nimport { unlock } from '../../../lock-unlock';\n\nconst { PostPanelRow } = unlock( editorPrivateApis );\n\nexport default function PostTemplate() {\n\t// Use internal state instead of a ref to make sure that the component\n\t// re-renders when the popover's anchor updates.\n\tconst [ popoverAnchor, setPopoverAnchor ] = useState( null );\n\t// Memoize popoverProps to avoid returning a new object every time.\n\tconst popoverProps = useMemo(\n\t\t() => ( { anchor: popoverAnchor, placement: 'bottom-end' } ),\n\t\t[ popoverAnchor ]\n\t);\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\tif ( ! settings.supportsTemplateMode ) {\n\t\t\treturn false;\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<PostPanelRow label={ __( 'Template' ) } ref={ setPopoverAnchor }>\n\t\t\t<Dropdown\n\t\t\t\tpopoverProps={ popoverProps }\n\t\t\t\tcontentClassName=\"edit-post-post-template__dialog\"\n\t\t\t\tfocusOnMount\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</PostPanelRow>\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 { supportsTemplateMode, availableTemplates } =\n\t\t\tselect( editorStore ).getEditorSettings();\n\t\tif ( ! supportsTemplateMode && availableTemplates[ templateSlug ] ) {\n\t\t\treturn availableTemplates[ templateSlug ];\n\t\t}\n\t\tconst template =\n\t\t\tselect( coreStore ).canUser( 'create', 'templates' ) &&\n\t\t\tselect( editPostStore ).getEditedPostTemplate();\n\t\treturn (\n\t\t\ttemplate?.title ||\n\t\t\ttemplate?.slug ||\n\t\t\tavailableTemplates?.[ templateSlug ]\n\t\t);\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 ?? __( 'Default template' ) }\n\t\t</Button>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,QAAQ,EAAEC,OAAO,QAAQ,oBAAoB;AACtD,SAASC,QAAQ,EAAEC,MAAM,QAAQ,uBAAuB;AACxD,SAASC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AAC7C,SAASC,SAAS,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,CAAEoB,YAAY,CAAE;IAC1C;IACA,MAAME,QAAQ,GACbhC,MAAM,CAAEZ,SAAU,CAAC,CAAC4B,OAAO,CAAE,QAAQ,EAAE,WAAY,CAAC,IACpDhB,MAAM,CAAEV,aAAc,CAAC,CAAC2C,qBAAqB,CAAC,CAAC;IAChD,OACCD,QAAQ,EAAEE,KAAK,IACfF,QAAQ,EAAEG,IAAI,IACdzB,kBAAkB,GAAIoB,YAAY,CAAE;EAEtC,CAAC,EAAE,EAAG,CAAC;EAEP,OACCb,aAAA,CAACrC,MAAM;IACNwD,SAAS,EAAC,iCAAiC;IAC3CC,OAAO,EAAC,UAAU;IAClB,iBAAgBd,MAAQ;IACxB,cACCM,aAAa,GACV/C,OAAO;IACP;IACAD,EAAE,CAAE,qBAAsB,CAAC,EAC3BgD,aACA,CAAC,GACDhD,EAAE,CAAE,iBAAkB,CACzB;IACD6C,OAAO,EAAGA;EAAS,GAEjBG,aAAa,aAAbA,aAAa,cAAbA,aAAa,GAAIhD,EAAE,CAAE,kBAAmB,CACnC,CAAC;AAEX"}
@@ -1,73 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { Icon, MenuGroup } from '@wordpress/components';
5
- import { PostPreviewButton, store as editorStore } from '@wordpress/editor';
6
- import { external } from '@wordpress/icons';
7
- import { __ } from '@wordpress/i18n';
8
- import { __experimentalPreviewOptions as PreviewOptions } from '@wordpress/block-editor';
9
- import { useDispatch, useSelect } from '@wordpress/data';
10
- import { store as coreStore } from '@wordpress/core-data';
11
-
12
- /**
13
- * Internal dependencies
14
- */
15
- import { store as editPostStore } from '../../store';
16
-
17
- export default function DevicePreview() {
18
- const {
19
- hasActiveMetaboxes,
20
- isPostSaveable,
21
- isViewable,
22
- deviceType,
23
- showIconLabels,
24
- } = useSelect( ( select ) => {
25
- const { getEditedPostAttribute } = select( editorStore );
26
- const { getPostType } = select( coreStore );
27
- const postType = getPostType( getEditedPostAttribute( 'type' ) );
28
-
29
- return {
30
- hasActiveMetaboxes: select( editPostStore ).hasMetaBoxes(),
31
- isPostSaveable: select( editorStore ).isEditedPostSaveable(),
32
- isViewable: postType?.viewable ?? false,
33
- deviceType:
34
- select( editPostStore ).__experimentalGetPreviewDeviceType(),
35
- showIconLabels:
36
- select( editPostStore ).isFeatureActive( 'showIconLabels' ),
37
- };
38
- }, [] );
39
- const { __experimentalSetPreviewDeviceType: setPreviewDeviceType } =
40
- useDispatch( editPostStore );
41
-
42
- return (
43
- <PreviewOptions
44
- isEnabled={ isPostSaveable }
45
- className="edit-post-post-preview-dropdown"
46
- deviceType={ deviceType }
47
- setDeviceType={ setPreviewDeviceType }
48
- label={ __( 'Preview' ) }
49
- showIconLabels={ showIconLabels }
50
- >
51
- { ( { onClose } ) =>
52
- isViewable && (
53
- <MenuGroup>
54
- <div className="edit-post-header-preview__grouping-external">
55
- <PostPreviewButton
56
- className="edit-post-header-preview__button-external"
57
- role="menuitem"
58
- forceIsAutosaveable={ hasActiveMetaboxes }
59
- textContent={
60
- <>
61
- { __( 'Preview in new tab' ) }
62
- <Icon icon={ external } />
63
- </>
64
- }
65
- onPreview={ onClose }
66
- />
67
- </div>
68
- </MenuGroup>
69
- )
70
- }
71
- </PreviewOptions>
72
- );
73
- }
@@ -1,82 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { __, isRTL } from '@wordpress/i18n';
5
- import { useSelect, useDispatch } from '@wordpress/data';
6
- import { BlockIcon, store as blockEditorStore } from '@wordpress/block-editor';
7
- import {
8
- Button,
9
- VisuallyHidden,
10
- __experimentalHStack as HStack,
11
- __experimentalText as Text,
12
- } from '@wordpress/components';
13
- import { layout, chevronLeftSmall, chevronRightSmall } from '@wordpress/icons';
14
- import { store as commandsStore } from '@wordpress/commands';
15
- import { displayShortcut } from '@wordpress/keycodes';
16
-
17
- /**
18
- * Internal dependencies
19
- */
20
- import { store as editPostStore } from '../../../store';
21
-
22
- function DocumentActions() {
23
- const { template } = useSelect( ( select ) => {
24
- const { getEditedPostTemplate } = select( editPostStore );
25
-
26
- return {
27
- template: getEditedPostTemplate(),
28
- };
29
- }, [] );
30
- const { clearSelectedBlock } = useDispatch( blockEditorStore );
31
- const { setIsEditingTemplate } = useDispatch( editPostStore );
32
- const { open: openCommandCenter } = useDispatch( commandsStore );
33
-
34
- if ( ! template ) {
35
- return null;
36
- }
37
-
38
- let templateTitle = __( 'Default' );
39
- if ( template?.title ) {
40
- templateTitle = template.title;
41
- } else if ( !! template ) {
42
- templateTitle = template.slug;
43
- }
44
-
45
- return (
46
- <div className="edit-post-document-actions">
47
- <Button
48
- className="edit-post-document-actions__back"
49
- onClick={ () => {
50
- clearSelectedBlock();
51
- setIsEditingTemplate( false );
52
- } }
53
- icon={ isRTL() ? chevronRightSmall : chevronLeftSmall }
54
- >
55
- { __( 'Back' ) }
56
- </Button>
57
- <Button
58
- className="edit-post-document-actions__command"
59
- onClick={ () => openCommandCenter() }
60
- >
61
- <HStack
62
- className="edit-post-document-actions__title"
63
- spacing={ 1 }
64
- justify="center"
65
- >
66
- <BlockIcon icon={ layout } />
67
- <Text size="body" as="h1">
68
- <VisuallyHidden as="span">
69
- { __( 'Editing template: ' ) }
70
- </VisuallyHidden>
71
- { templateTitle }
72
- </Text>
73
- </HStack>
74
- <span className="edit-post-document-actions__shortcut">
75
- { displayShortcut.primary( 'k' ) }
76
- </span>
77
- </Button>
78
- </div>
79
- );
80
- }
81
-
82
- export default DocumentActions;
@@ -1,64 +0,0 @@
1
- .edit-post-document-actions {
2
- display: flex;
3
- align-items: center;
4
- gap: $grid-unit;
5
- height: $button-size;
6
- justify-content: space-between;
7
- // Flex items will, by default, refuse to shrink below a minimum
8
- // intrinsic width. In order to shrink this flexbox item, and
9
- // subsequently truncate child text, we set an explicit min-width.
10
- // See https://dev.w3.org/csswg/css-flexbox/#min-size-auto
11
- min-width: 0;
12
- background: $gray-100;
13
- border-radius: 4px;
14
- width: min(100%, 450px);
15
-
16
- .components-button {
17
- &:hover {
18
- color: var(--wp-block-synced-color);
19
- background: $gray-200;
20
- }
21
- }
22
- }
23
-
24
- .edit-post-document-actions__command {
25
- flex-grow: 1;
26
- color: var(--wp-block-synced-color);
27
- overflow: hidden;
28
- }
29
-
30
- .edit-post-document-actions__title {
31
- flex-grow: 1;
32
- color: var(--wp-block-synced-color);
33
- overflow: hidden;
34
-
35
- &:hover {
36
- color: var(--wp-block-synced-color);
37
- }
38
-
39
- .block-editor-block-icon {
40
- flex-shrink: 0;
41
- }
42
-
43
- h1 {
44
- white-space: nowrap;
45
- overflow: hidden;
46
- text-overflow: ellipsis;
47
- color: var(--wp-block-synced-color);
48
- }
49
- }
50
-
51
- .edit-post-document-actions__shortcut {
52
- color: $gray-800;
53
- }
54
-
55
- .edit-post-document-actions__back.components-button.has-icon.has-text {
56
- min-width: $button-size;
57
- flex-shrink: 0;
58
- color: $gray-700;
59
- gap: 0;
60
-
61
- &:hover {
62
- color: currentColor;
63
- }
64
- }
@@ -1,140 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { useSelect, useDispatch } from '@wordpress/data';
5
- import { store as editorStore } from '@wordpress/editor';
6
- import { useState } from '@wordpress/element';
7
- import { serialize, createBlock } from '@wordpress/blocks';
8
- import {
9
- Modal,
10
- TextControl,
11
- Button,
12
- __experimentalHStack as HStack,
13
- __experimentalVStack as VStack,
14
- } from '@wordpress/components';
15
- import { __ } from '@wordpress/i18n';
16
- import { cleanForSlug } from '@wordpress/url';
17
-
18
- /**
19
- * Internal dependencies
20
- */
21
- import { store as editPostStore } from '../../../store';
22
-
23
- const DEFAULT_TITLE = __( 'Custom Template' );
24
-
25
- export default function PostTemplateCreateModal( { onClose } ) {
26
- const defaultBlockTemplate = useSelect(
27
- ( select ) =>
28
- select( editorStore ).getEditorSettings().defaultBlockTemplate,
29
- []
30
- );
31
-
32
- const { __unstableCreateTemplate, __unstableSwitchToTemplateMode } =
33
- useDispatch( editPostStore );
34
-
35
- const [ title, setTitle ] = useState( '' );
36
-
37
- const [ isBusy, setIsBusy ] = useState( false );
38
-
39
- const cancel = () => {
40
- setTitle( '' );
41
- onClose();
42
- };
43
-
44
- const submit = async ( event ) => {
45
- event.preventDefault();
46
-
47
- if ( isBusy ) {
48
- return;
49
- }
50
-
51
- setIsBusy( true );
52
-
53
- const newTemplateContent =
54
- defaultBlockTemplate ??
55
- serialize( [
56
- createBlock(
57
- 'core/group',
58
- {
59
- tagName: 'header',
60
- layout: { inherit: true },
61
- },
62
- [
63
- createBlock( 'core/site-title' ),
64
- createBlock( 'core/site-tagline' ),
65
- ]
66
- ),
67
- createBlock( 'core/separator' ),
68
- createBlock(
69
- 'core/group',
70
- {
71
- tagName: 'main',
72
- },
73
- [
74
- createBlock(
75
- 'core/group',
76
- {
77
- layout: { inherit: true },
78
- },
79
- [ createBlock( 'core/post-title' ) ]
80
- ),
81
- createBlock( 'core/post-content', {
82
- layout: { inherit: true },
83
- } ),
84
- ]
85
- ),
86
- ] );
87
-
88
- await __unstableCreateTemplate( {
89
- slug: cleanForSlug( title || DEFAULT_TITLE ),
90
- content: newTemplateContent,
91
- title: title || DEFAULT_TITLE,
92
- } );
93
-
94
- setIsBusy( false );
95
- cancel();
96
-
97
- __unstableSwitchToTemplateMode( true );
98
- };
99
-
100
- return (
101
- <Modal
102
- title={ __( 'Create custom template' ) }
103
- onRequestClose={ cancel }
104
- className="edit-post-post-template__create-modal"
105
- >
106
- <form
107
- className="edit-post-post-template__create-form"
108
- onSubmit={ submit }
109
- >
110
- <VStack spacing="3">
111
- <TextControl
112
- __nextHasNoMarginBottom
113
- label={ __( 'Name' ) }
114
- value={ title }
115
- onChange={ setTitle }
116
- placeholder={ DEFAULT_TITLE }
117
- disabled={ isBusy }
118
- help={ __(
119
- 'Describe the template, e.g. "Post with sidebar". A custom template can be manually applied to any post or page.'
120
- ) }
121
- />
122
- <HStack justify="right">
123
- <Button variant="tertiary" onClick={ cancel }>
124
- { __( 'Cancel' ) }
125
- </Button>
126
-
127
- <Button
128
- variant="primary"
129
- type="submit"
130
- isBusy={ isBusy }
131
- aria-disabled={ isBusy }
132
- >
133
- { __( 'Create' ) }
134
- </Button>
135
- </HStack>
136
- </VStack>
137
- </form>
138
- </Modal>
139
- );
140
- }