@wordpress/editor 13.31.0 → 13.32.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 (157) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/README.md +857 -0
  3. package/build/components/block-settings-menu/plugin-block-settings-menu-item.js +107 -0
  4. package/build/components/block-settings-menu/plugin-block-settings-menu-item.js.map +1 -0
  5. package/build/components/commands/index.js +1 -1
  6. package/build/components/commands/index.js.map +1 -1
  7. package/build/components/deprecated.js +158 -0
  8. package/build/components/deprecated.js.map +1 -1
  9. package/build/components/document-bar/index.js +5 -8
  10. package/build/components/document-bar/index.js.map +1 -1
  11. package/build/components/editor-canvas/edit-template-blocks-notification.js +2 -39
  12. package/build/components/editor-canvas/edit-template-blocks-notification.js.map +1 -1
  13. package/build/components/editor-canvas/index.js +3 -0
  14. package/build/components/editor-canvas/index.js.map +1 -1
  15. package/build/components/entities-saved-states/index.js +11 -85
  16. package/build/components/entities-saved-states/index.js.map +1 -1
  17. package/build/components/index.js +24 -0
  18. package/build/components/index.js.map +1 -1
  19. package/build/components/inserter-sidebar/index.js +5 -1
  20. package/build/components/inserter-sidebar/index.js.map +1 -1
  21. package/build/components/list-view-sidebar/index.js +2 -1
  22. package/build/components/list-view-sidebar/index.js.map +1 -1
  23. package/build/components/pattern-overrides-panel/index.js +30 -0
  24. package/build/components/pattern-overrides-panel/index.js.map +1 -0
  25. package/build/components/plugin-post-publish-panel/index.js +68 -0
  26. package/build/components/plugin-post-publish-panel/index.js.map +1 -0
  27. package/build/components/plugin-pre-publish-panel/index.js +71 -0
  28. package/build/components/plugin-pre-publish-panel/index.js.map +1 -0
  29. package/build/components/post-actions/actions.js +455 -0
  30. package/build/components/post-actions/actions.js.map +1 -0
  31. package/build/components/post-card-panel/index.js +93 -0
  32. package/build/components/post-card-panel/index.js.map +1 -0
  33. package/build/components/post-title/index.native.js +1 -1
  34. package/build/components/post-title/index.native.js.map +1 -1
  35. package/build/components/provider/disable-non-page-content-blocks.js +36 -20
  36. package/build/components/provider/disable-non-page-content-blocks.js.map +1 -1
  37. package/build/components/provider/use-block-editor-settings.js +8 -9
  38. package/build/components/provider/use-block-editor-settings.js.map +1 -1
  39. package/build/components/template-areas/index.js +70 -0
  40. package/build/components/template-areas/index.js.map +1 -0
  41. package/build/hooks/use-select-nearest-editable-block.js +87 -0
  42. package/build/hooks/use-select-nearest-editable-block.js.map +1 -0
  43. package/build/private-apis.js +6 -0
  44. package/build/private-apis.js.map +1 -1
  45. package/build/store/actions.js +46 -6
  46. package/build/store/actions.js.map +1 -1
  47. package/build/store/constants.js +3 -1
  48. package/build/store/constants.js.map +1 -1
  49. package/build/store/private-actions.js +80 -1
  50. package/build/store/private-actions.js.map +1 -1
  51. package/build/store/private-selectors.js +56 -3
  52. package/build/store/private-selectors.js.map +1 -1
  53. package/build/store/reducer.js +14 -1
  54. package/build/store/reducer.js.map +1 -1
  55. package/build/store/selectors.js +21 -11
  56. package/build/store/selectors.js.map +1 -1
  57. package/build/store/utils/get-filtered-template-parts.js +71 -0
  58. package/build/store/utils/get-filtered-template-parts.js.map +1 -0
  59. package/build-module/components/block-settings-menu/plugin-block-settings-menu-item.js +100 -0
  60. package/build-module/components/block-settings-menu/plugin-block-settings-menu-item.js.map +1 -0
  61. package/build-module/components/commands/index.js +1 -1
  62. package/build-module/components/commands/index.js.map +1 -1
  63. package/build-module/components/deprecated.js +159 -0
  64. package/build-module/components/deprecated.js.map +1 -1
  65. package/build-module/components/document-bar/index.js +6 -9
  66. package/build-module/components/document-bar/index.js.map +1 -1
  67. package/build-module/components/editor-canvas/edit-template-blocks-notification.js +4 -41
  68. package/build-module/components/editor-canvas/edit-template-blocks-notification.js.map +1 -1
  69. package/build-module/components/editor-canvas/index.js +3 -0
  70. package/build-module/components/editor-canvas/index.js.map +1 -1
  71. package/build-module/components/entities-saved-states/index.js +11 -85
  72. package/build-module/components/entities-saved-states/index.js.map +1 -1
  73. package/build-module/components/index.js +3 -0
  74. package/build-module/components/index.js.map +1 -1
  75. package/build-module/components/inserter-sidebar/index.js +5 -1
  76. package/build-module/components/inserter-sidebar/index.js.map +1 -1
  77. package/build-module/components/list-view-sidebar/index.js +2 -1
  78. package/build-module/components/list-view-sidebar/index.js.map +1 -1
  79. package/build-module/components/pattern-overrides-panel/index.js +23 -0
  80. package/build-module/components/pattern-overrides-panel/index.js.map +1 -0
  81. package/build-module/components/plugin-post-publish-panel/index.js +61 -0
  82. package/build-module/components/plugin-post-publish-panel/index.js.map +1 -0
  83. package/build-module/components/plugin-pre-publish-panel/index.js +64 -0
  84. package/build-module/components/plugin-pre-publish-panel/index.js.map +1 -0
  85. package/build-module/components/post-actions/actions.js +444 -0
  86. package/build-module/components/post-actions/actions.js.map +1 -0
  87. package/build-module/components/post-card-panel/index.js +85 -0
  88. package/build-module/components/post-card-panel/index.js.map +1 -0
  89. package/build-module/components/post-title/index.native.js +1 -1
  90. package/build-module/components/post-title/index.native.js.map +1 -1
  91. package/build-module/components/provider/disable-non-page-content-blocks.js +36 -20
  92. package/build-module/components/provider/disable-non-page-content-blocks.js.map +1 -1
  93. package/build-module/components/provider/use-block-editor-settings.js +9 -10
  94. package/build-module/components/provider/use-block-editor-settings.js.map +1 -1
  95. package/build-module/components/template-areas/index.js +63 -0
  96. package/build-module/components/template-areas/index.js.map +1 -0
  97. package/build-module/hooks/use-select-nearest-editable-block.js +80 -0
  98. package/build-module/hooks/use-select-nearest-editable-block.js.map +1 -0
  99. package/build-module/private-apis.js +6 -0
  100. package/build-module/private-apis.js.map +1 -1
  101. package/build-module/store/actions.js +37 -3
  102. package/build-module/store/actions.js.map +1 -1
  103. package/build-module/store/constants.js +2 -0
  104. package/build-module/store/constants.js.map +1 -1
  105. package/build-module/store/private-actions.js +78 -0
  106. package/build-module/store/private-actions.js.map +1 -1
  107. package/build-module/store/private-selectors.js +54 -3
  108. package/build-module/store/private-selectors.js.map +1 -1
  109. package/build-module/store/reducer.js +13 -1
  110. package/build-module/store/reducer.js.map +1 -1
  111. package/build-module/store/selectors.js +19 -10
  112. package/build-module/store/selectors.js.map +1 -1
  113. package/build-module/store/utils/get-filtered-template-parts.js +64 -0
  114. package/build-module/store/utils/get-filtered-template-parts.js.map +1 -0
  115. package/build-style/style-rtl.css +70 -27
  116. package/build-style/style.css +70 -27
  117. package/package.json +35 -35
  118. package/src/components/block-settings-menu/plugin-block-settings-menu-item.js +108 -0
  119. package/src/components/commands/index.js +1 -1
  120. package/src/components/deprecated.js +157 -0
  121. package/src/components/document-bar/index.js +9 -15
  122. package/src/components/document-bar/style.scss +9 -12
  123. package/src/components/document-tools/style.scss +4 -11
  124. package/src/components/editor-canvas/edit-template-blocks-notification.js +6 -56
  125. package/src/components/editor-canvas/index.js +4 -0
  126. package/src/components/entities-saved-states/index.js +12 -113
  127. package/src/components/index.js +3 -0
  128. package/src/components/inserter-sidebar/index.js +7 -1
  129. package/src/components/list-view-sidebar/index.js +1 -0
  130. package/src/components/list-view-sidebar/style.scss +1 -1
  131. package/src/components/pattern-overrides-panel/index.js +26 -0
  132. package/src/components/plugin-post-publish-panel/index.js +64 -0
  133. package/src/components/plugin-post-publish-panel/test/__snapshots__/index.js.snap +39 -0
  134. package/src/components/plugin-post-publish-panel/test/index.js +33 -0
  135. package/src/components/plugin-pre-publish-panel/index.js +67 -0
  136. package/src/components/plugin-pre-publish-panel/test/index.js +33 -0
  137. package/src/components/post-actions/actions.js +582 -0
  138. package/src/components/post-card-panel/index.js +108 -0
  139. package/src/components/post-card-panel/style.scss +32 -0
  140. package/src/components/post-featured-image/style.scss +3 -2
  141. package/src/components/post-title/index.native.js +1 -1
  142. package/src/components/provider/disable-non-page-content-blocks.js +40 -20
  143. package/src/components/provider/test/disable-non-page-content-blocks.js +35 -14
  144. package/src/components/provider/use-block-editor-settings.js +11 -11
  145. package/src/components/template-areas/index.js +85 -0
  146. package/src/components/template-areas/style.scss +23 -0
  147. package/src/hooks/use-select-nearest-editable-block.js +95 -0
  148. package/src/private-apis.js +6 -0
  149. package/src/store/actions.js +37 -3
  150. package/src/store/constants.js +2 -0
  151. package/src/store/private-actions.js +111 -0
  152. package/src/store/private-selectors.js +105 -17
  153. package/src/store/reducer.js +13 -0
  154. package/src/store/selectors.js +50 -40
  155. package/src/store/utils/get-filtered-template-parts.js +69 -0
  156. package/src/store/utils/test/get-filtered-template-parts.js +189 -0
  157. package/src/style.scss +2 -0
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useSelect","privateApis","patternsPrivateApis","store","editorStore","unlock","OverridesPanel","PatternOverridesPanel","supportsPatternOverridesPanel","select","getCurrentPostType","createElement"],"sources":["@wordpress/editor/src/components/pattern-overrides-panel/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { privateApis as patternsPrivateApis } from '@wordpress/patterns';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\n\nconst { OverridesPanel } = unlock( patternsPrivateApis );\n\nexport default function PatternOverridesPanel() {\n\tconst supportsPatternOverridesPanel = useSelect(\n\t\t( select ) => select( editorStore ).getCurrentPostType() === 'wp_block',\n\t\t[]\n\t);\n\n\tif ( ! supportsPatternOverridesPanel ) {\n\t\treturn null;\n\t}\n\n\treturn <OverridesPanel />;\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,WAAW,IAAIC,mBAAmB,QAAQ,qBAAqB;;AAExE;AACA;AACA;AACA,SAASC,KAAK,IAAIC,WAAW,QAAQ,aAAa;AAClD,SAASC,MAAM,QAAQ,mBAAmB;AAE1C,MAAM;EAAEC;AAAe,CAAC,GAAGD,MAAM,CAAEH,mBAAoB,CAAC;AAExD,eAAe,SAASK,qBAAqBA,CAAA,EAAG;EAC/C,MAAMC,6BAA6B,GAAGR,SAAS,CAC5CS,MAAM,IAAMA,MAAM,CAAEL,WAAY,CAAC,CAACM,kBAAkB,CAAC,CAAC,KAAK,UAAU,EACvE,EACD,CAAC;EAED,IAAK,CAAEF,6BAA6B,EAAG;IACtC,OAAO,IAAI;EACZ;EAEA,OAAOG,aAAA,CAACL,cAAc,MAAE,CAAC;AAC1B"}
@@ -0,0 +1,61 @@
1
+ import { createElement } from "react";
2
+ /**
3
+ * WordPress dependencies
4
+ */
5
+ import { usePluginContext } from '@wordpress/plugins';
6
+ import { createSlotFill, PanelBody } from '@wordpress/components';
7
+ const {
8
+ Fill,
9
+ Slot
10
+ } = createSlotFill('PluginPostPublishPanel');
11
+
12
+ /**
13
+ * Renders provided content to the post-publish panel in the publish flow
14
+ * (side panel that opens after a user publishes the post).
15
+ *
16
+ * @param {Object} props Component properties.
17
+ * @param {string} [props.className] An optional class name added to the panel.
18
+ * @param {string} [props.title] Title displayed at the top of the panel.
19
+ * @param {boolean} [props.initialOpen=false] Whether to have the panel initially opened. When no title is provided it is always opened.
20
+ * @param {WPBlockTypeIconRender} [props.icon=inherits from the plugin] The [Dashicon](https://developer.wordpress.org/resource/dashicons/) icon slug string, or an SVG WP element, to be rendered when the sidebar is pinned to toolbar.
21
+ * @param {Element} props.children Children to be rendered
22
+ *
23
+ * @example
24
+ * ```jsx
25
+ * // Using ESNext syntax
26
+ * import { __ } from '@wordpress/i18n';
27
+ * import { PluginPostPublishPanel } from '@wordpress/edit-post';
28
+ *
29
+ * const MyPluginPostPublishPanel = () => (
30
+ * <PluginPostPublishPanel
31
+ * className="my-plugin-post-publish-panel"
32
+ * title={ __( 'My panel title' ) }
33
+ * initialOpen={ true }
34
+ * >
35
+ * { __( 'My panel content' ) }
36
+ * </PluginPostPublishPanel>
37
+ * );
38
+ * ```
39
+ *
40
+ * @return {Component} The component to be rendered.
41
+ */
42
+ const PluginPostPublishPanel = ({
43
+ children,
44
+ className,
45
+ title,
46
+ initialOpen = false,
47
+ icon
48
+ }) => {
49
+ const {
50
+ icon: pluginIcon
51
+ } = usePluginContext();
52
+ return createElement(Fill, null, createElement(PanelBody, {
53
+ className: className,
54
+ initialOpen: initialOpen || !title,
55
+ title: title,
56
+ icon: icon !== null && icon !== void 0 ? icon : pluginIcon
57
+ }, children));
58
+ };
59
+ PluginPostPublishPanel.Slot = Slot;
60
+ export default PluginPostPublishPanel;
61
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["usePluginContext","createSlotFill","PanelBody","Fill","Slot","PluginPostPublishPanel","children","className","title","initialOpen","icon","pluginIcon","createElement"],"sources":["@wordpress/editor/src/components/plugin-post-publish-panel/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { usePluginContext } from '@wordpress/plugins';\nimport { createSlotFill, PanelBody } from '@wordpress/components';\n\nconst { Fill, Slot } = createSlotFill( 'PluginPostPublishPanel' );\n\n/**\n * Renders provided content to the post-publish panel in the publish flow\n * (side panel that opens after a user publishes the post).\n *\n * @param {Object} props Component properties.\n * @param {string} [props.className] An optional class name added to the panel.\n * @param {string} [props.title] Title displayed at the top of the panel.\n * @param {boolean} [props.initialOpen=false] Whether to have the panel initially opened. When no title is provided it is always opened.\n * @param {WPBlockTypeIconRender} [props.icon=inherits from the plugin] The [Dashicon](https://developer.wordpress.org/resource/dashicons/) icon slug string, or an SVG WP element, to be rendered when the sidebar is pinned to toolbar.\n * @param {Element} props.children Children to be rendered\n *\n * @example\n * ```jsx\n * // Using ESNext syntax\n * import { __ } from '@wordpress/i18n';\n * import { PluginPostPublishPanel } from '@wordpress/edit-post';\n *\n * const MyPluginPostPublishPanel = () => (\n * \t<PluginPostPublishPanel\n * \t\tclassName=\"my-plugin-post-publish-panel\"\n * \t\ttitle={ __( 'My panel title' ) }\n * \t\tinitialOpen={ true }\n * \t>\n * { __( 'My panel content' ) }\n * \t</PluginPostPublishPanel>\n * );\n * ```\n *\n * @return {Component} The component to be rendered.\n */\nconst PluginPostPublishPanel = ( {\n\tchildren,\n\tclassName,\n\ttitle,\n\tinitialOpen = false,\n\ticon,\n} ) => {\n\tconst { icon: pluginIcon } = usePluginContext();\n\n\treturn (\n\t\t<Fill>\n\t\t\t<PanelBody\n\t\t\t\tclassName={ className }\n\t\t\t\tinitialOpen={ initialOpen || ! title }\n\t\t\t\ttitle={ title }\n\t\t\t\ticon={ icon ?? pluginIcon }\n\t\t\t>\n\t\t\t\t{ children }\n\t\t\t</PanelBody>\n\t\t</Fill>\n\t);\n};\n\nPluginPostPublishPanel.Slot = Slot;\n\nexport default PluginPostPublishPanel;\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,gBAAgB,QAAQ,oBAAoB;AACrD,SAASC,cAAc,EAAEC,SAAS,QAAQ,uBAAuB;AAEjE,MAAM;EAAEC,IAAI;EAAEC;AAAK,CAAC,GAAGH,cAAc,CAAE,wBAAyB,CAAC;;AAEjE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMI,sBAAsB,GAAGA,CAAE;EAChCC,QAAQ;EACRC,SAAS;EACTC,KAAK;EACLC,WAAW,GAAG,KAAK;EACnBC;AACD,CAAC,KAAM;EACN,MAAM;IAAEA,IAAI,EAAEC;EAAW,CAAC,GAAGX,gBAAgB,CAAC,CAAC;EAE/C,OACCY,aAAA,CAACT,IAAI,QACJS,aAAA,CAACV,SAAS;IACTK,SAAS,EAAGA,SAAW;IACvBE,WAAW,EAAGA,WAAW,IAAI,CAAED,KAAO;IACtCA,KAAK,EAAGA,KAAO;IACfE,IAAI,EAAGA,IAAI,aAAJA,IAAI,cAAJA,IAAI,GAAIC;EAAY,GAEzBL,QACQ,CACN,CAAC;AAET,CAAC;AAEDD,sBAAsB,CAACD,IAAI,GAAGA,IAAI;AAElC,eAAeC,sBAAsB"}
@@ -0,0 +1,64 @@
1
+ import { createElement } from "react";
2
+ /**
3
+ * WordPress dependencies
4
+ */
5
+ import { createSlotFill, PanelBody } from '@wordpress/components';
6
+ import { usePluginContext } from '@wordpress/plugins';
7
+ const {
8
+ Fill,
9
+ Slot
10
+ } = createSlotFill('PluginPrePublishPanel');
11
+
12
+ /**
13
+ * Renders provided content to the pre-publish side panel in the publish flow
14
+ * (side panel that opens when a user first pushes "Publish" from the main editor).
15
+ *
16
+ * @param {Object} props Component props.
17
+ * @param {string} [props.className] An optional class name added to the panel.
18
+ * @param {string} [props.title] Title displayed at the top of the panel.
19
+ * @param {boolean} [props.initialOpen=false] Whether to have the panel initially opened.
20
+ * When no title is provided it is always opened.
21
+ * @param {WPBlockTypeIconRender} [props.icon=inherits from the plugin] The [Dashicon](https://developer.wordpress.org/resource/dashicons/)
22
+ * icon slug string, or an SVG WP element, to be rendered when
23
+ * the sidebar is pinned to toolbar.
24
+ * @param {Element} props.children Children to be rendered
25
+ *
26
+ * @example
27
+ * ```jsx
28
+ * // Using ESNext syntax
29
+ * import { __ } from '@wordpress/i18n';
30
+ * import { PluginPrePublishPanel } from '@wordpress/edit-post';
31
+ *
32
+ * const MyPluginPrePublishPanel = () => (
33
+ * <PluginPrePublishPanel
34
+ * className="my-plugin-pre-publish-panel"
35
+ * title={ __( 'My panel title' ) }
36
+ * initialOpen={ true }
37
+ * >
38
+ * { __( 'My panel content' ) }
39
+ * </PluginPrePublishPanel>
40
+ * );
41
+ * ```
42
+ *
43
+ * @return {Component} The component to be rendered.
44
+ */
45
+ const PluginPrePublishPanel = ({
46
+ children,
47
+ className,
48
+ title,
49
+ initialOpen = false,
50
+ icon
51
+ }) => {
52
+ const {
53
+ icon: pluginIcon
54
+ } = usePluginContext();
55
+ return createElement(Fill, null, createElement(PanelBody, {
56
+ className: className,
57
+ initialOpen: initialOpen || !title,
58
+ title: title,
59
+ icon: icon !== null && icon !== void 0 ? icon : pluginIcon
60
+ }, children));
61
+ };
62
+ PluginPrePublishPanel.Slot = Slot;
63
+ export default PluginPrePublishPanel;
64
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createSlotFill","PanelBody","usePluginContext","Fill","Slot","PluginPrePublishPanel","children","className","title","initialOpen","icon","pluginIcon","createElement"],"sources":["@wordpress/editor/src/components/plugin-pre-publish-panel/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createSlotFill, PanelBody } from '@wordpress/components';\nimport { usePluginContext } from '@wordpress/plugins';\n\nconst { Fill, Slot } = createSlotFill( 'PluginPrePublishPanel' );\n\n/**\n * Renders provided content to the pre-publish side panel in the publish flow\n * (side panel that opens when a user first pushes \"Publish\" from the main editor).\n *\n * @param {Object} props Component props.\n * @param {string} [props.className] An optional class name added to the panel.\n * @param {string} [props.title] Title displayed at the top of the panel.\n * @param {boolean} [props.initialOpen=false] Whether to have the panel initially opened.\n * When no title is provided it is always opened.\n * @param {WPBlockTypeIconRender} [props.icon=inherits from the plugin] The [Dashicon](https://developer.wordpress.org/resource/dashicons/)\n * icon slug string, or an SVG WP element, to be rendered when\n * the sidebar is pinned to toolbar.\n * @param {Element} props.children Children to be rendered\n *\n * @example\n * ```jsx\n * // Using ESNext syntax\n * import { __ } from '@wordpress/i18n';\n * import { PluginPrePublishPanel } from '@wordpress/edit-post';\n *\n * const MyPluginPrePublishPanel = () => (\n * \t<PluginPrePublishPanel\n * \t\tclassName=\"my-plugin-pre-publish-panel\"\n * \t\ttitle={ __( 'My panel title' ) }\n * \t\tinitialOpen={ true }\n * \t>\n * \t { __( 'My panel content' ) }\n * \t</PluginPrePublishPanel>\n * );\n * ```\n *\n * @return {Component} The component to be rendered.\n */\nconst PluginPrePublishPanel = ( {\n\tchildren,\n\tclassName,\n\ttitle,\n\tinitialOpen = false,\n\ticon,\n} ) => {\n\tconst { icon: pluginIcon } = usePluginContext();\n\n\treturn (\n\t\t<Fill>\n\t\t\t<PanelBody\n\t\t\t\tclassName={ className }\n\t\t\t\tinitialOpen={ initialOpen || ! title }\n\t\t\t\ttitle={ title }\n\t\t\t\ticon={ icon ?? pluginIcon }\n\t\t\t>\n\t\t\t\t{ children }\n\t\t\t</PanelBody>\n\t\t</Fill>\n\t);\n};\n\nPluginPrePublishPanel.Slot = Slot;\n\nexport default PluginPrePublishPanel;\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,cAAc,EAAEC,SAAS,QAAQ,uBAAuB;AACjE,SAASC,gBAAgB,QAAQ,oBAAoB;AAErD,MAAM;EAAEC,IAAI;EAAEC;AAAK,CAAC,GAAGJ,cAAc,CAAE,uBAAwB,CAAC;;AAEhE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMK,qBAAqB,GAAGA,CAAE;EAC/BC,QAAQ;EACRC,SAAS;EACTC,KAAK;EACLC,WAAW,GAAG,KAAK;EACnBC;AACD,CAAC,KAAM;EACN,MAAM;IAAEA,IAAI,EAAEC;EAAW,CAAC,GAAGT,gBAAgB,CAAC,CAAC;EAE/C,OACCU,aAAA,CAACT,IAAI,QACJS,aAAA,CAACX,SAAS;IACTM,SAAS,EAAGA,SAAW;IACvBE,WAAW,EAAGA,WAAW,IAAI,CAAED,KAAO;IACtCA,KAAK,EAAGA,KAAO;IACfE,IAAI,EAAGA,IAAI,aAAJA,IAAI,cAAJA,IAAI,GAAIC;EAAY,GAEzBL,QACQ,CACN,CAAC;AAET,CAAC;AAEDD,qBAAqB,CAACD,IAAI,GAAGA,IAAI;AAEjC,eAAeC,qBAAqB"}
@@ -0,0 +1,444 @@
1
+ import { createElement } from "react";
2
+ /**
3
+ * WordPress dependencies
4
+ */
5
+ import { external, trash, edit, backup } from '@wordpress/icons';
6
+ import { addQueryArgs } from '@wordpress/url';
7
+ import { useDispatch } from '@wordpress/data';
8
+ import { decodeEntities } from '@wordpress/html-entities';
9
+ import { store as coreStore } from '@wordpress/core-data';
10
+ import { __, _n, sprintf } from '@wordpress/i18n';
11
+ import { store as noticesStore } from '@wordpress/notices';
12
+ import { useMemo, useState } from '@wordpress/element';
13
+ import { Button, TextControl, __experimentalText as Text, __experimentalHStack as HStack, __experimentalVStack as VStack } from '@wordpress/components';
14
+ function getItemTitle(item) {
15
+ if (typeof item.title === 'string') {
16
+ return decodeEntities(item.title);
17
+ }
18
+ return decodeEntities(item.title?.rendered || '');
19
+ }
20
+ export const trashPostAction = {
21
+ id: 'move-to-trash',
22
+ label: __('Move to Trash'),
23
+ isPrimary: true,
24
+ icon: trash,
25
+ isEligible({
26
+ status
27
+ }) {
28
+ return status !== 'trash';
29
+ },
30
+ supportsBulk: true,
31
+ hideModalHeader: true,
32
+ RenderModal: ({
33
+ items: posts,
34
+ closeModal,
35
+ onActionPerformed
36
+ }) => {
37
+ const {
38
+ createSuccessNotice,
39
+ createErrorNotice
40
+ } = useDispatch(noticesStore);
41
+ const {
42
+ deleteEntityRecord
43
+ } = useDispatch(coreStore);
44
+ return createElement(VStack, {
45
+ spacing: "5"
46
+ }, createElement(Text, null, posts.length === 1 ? sprintf(
47
+ // translators: %s: The page's title.
48
+ __('Are you sure you want to delete "%s"?'), getItemTitle(posts[0])) : sprintf(
49
+ // translators: %d: The number of pages (2 or more).
50
+ _n('Are you sure you want to delete %d page?', 'Are you sure you want to delete %d pages?', posts.length), posts.length)), createElement(HStack, {
51
+ justify: "right"
52
+ }, createElement(Button, {
53
+ variant: "tertiary",
54
+ onClick: closeModal
55
+ }, __('Cancel')), createElement(Button, {
56
+ variant: "primary",
57
+ onClick: async () => {
58
+ const promiseResult = await Promise.allSettled(posts.map(post => {
59
+ return deleteEntityRecord('postType', post.type, post.id, {}, {
60
+ throwOnError: true
61
+ });
62
+ }));
63
+ // If all the promises were fulfilled with success.
64
+ if (promiseResult.every(({
65
+ status
66
+ }) => status === 'fulfilled')) {
67
+ let successMessage;
68
+ if (promiseResult.length === 1) {
69
+ successMessage = sprintf( /* translators: The posts's title. */
70
+ __('"%s" moved to the Trash.'), getItemTitle(posts[0]));
71
+ } else {
72
+ successMessage = __('Pages moved to the Trash.');
73
+ }
74
+ createSuccessNotice(successMessage, {
75
+ type: 'snackbar',
76
+ id: 'edit-site-page-trashed'
77
+ });
78
+ } else {
79
+ // If there was at lease one failure.
80
+ let errorMessage;
81
+ // If we were trying to move a single post to the trash.
82
+ if (promiseResult.length === 1) {
83
+ if (promiseResult[0].reason?.message) {
84
+ errorMessage = promiseResult[0].reason.message;
85
+ } else {
86
+ errorMessage = __('An error occurred while moving the post to the trash.');
87
+ }
88
+ // If we were trying to move multiple posts to the trash
89
+ } else {
90
+ const errorMessages = new Set();
91
+ const failedPromises = promiseResult.filter(({
92
+ status
93
+ }) => status === 'rejected');
94
+ for (const failedPromise of failedPromises) {
95
+ if (failedPromise.reason?.message) {
96
+ errorMessages.add(failedPromise.reason.message);
97
+ }
98
+ }
99
+ if (errorMessages.size === 0) {
100
+ errorMessage = __('An error occurred while moving the posts to the trash.');
101
+ } else if (errorMessages.size === 1) {
102
+ errorMessage = sprintf( /* translators: %s: an error message */
103
+ __('An error occurred while moving the posts to the trash: %s'), [...errorMessages][0]);
104
+ } else {
105
+ errorMessage = sprintf( /* translators: %s: a list of comma separated error messages */
106
+ __('Some errors occurred while moving the pages to the trash: %s'), [...errorMessages].join(','));
107
+ }
108
+ createErrorNotice(errorMessage, {
109
+ type: 'snackbar'
110
+ });
111
+ }
112
+ }
113
+ if (onActionPerformed) {
114
+ onActionPerformed(posts);
115
+ }
116
+ closeModal();
117
+ }
118
+ }, __('Delete'))));
119
+ }
120
+ };
121
+ export function usePermanentlyDeletePostAction() {
122
+ const {
123
+ createSuccessNotice,
124
+ createErrorNotice
125
+ } = useDispatch(noticesStore);
126
+ const {
127
+ deleteEntityRecord
128
+ } = useDispatch(coreStore);
129
+ return useMemo(() => ({
130
+ id: 'permanently-delete',
131
+ label: __('Permanently delete'),
132
+ supportsBulk: true,
133
+ isEligible({
134
+ status
135
+ }) {
136
+ return status === 'trash';
137
+ },
138
+ async callback(posts, onActionPerformed) {
139
+ const promiseResult = await Promise.allSettled(posts.map(post => {
140
+ return deleteEntityRecord('postType', post.type, post.id, {
141
+ force: true
142
+ }, {
143
+ throwOnError: true
144
+ });
145
+ }));
146
+ // If all the promises were fulfilled with success.
147
+ if (promiseResult.every(({
148
+ status
149
+ }) => status === 'fulfilled')) {
150
+ let successMessage;
151
+ if (promiseResult.length === 1) {
152
+ successMessage = sprintf( /* translators: The posts's title. */
153
+ __('"%s" permanently deleted.'), getItemTitle(posts[0]));
154
+ } else {
155
+ successMessage = __('The posts were permanently deleted.');
156
+ }
157
+ createSuccessNotice(successMessage, {
158
+ type: 'snackbar',
159
+ id: 'edit-site-post-permanently-deleted'
160
+ });
161
+ if (onActionPerformed) {
162
+ onActionPerformed(posts);
163
+ }
164
+ } else {
165
+ // If there was at lease one failure.
166
+ let errorMessage;
167
+ // If we were trying to permanently delete a single post.
168
+ if (promiseResult.length === 1) {
169
+ if (promiseResult[0].reason?.message) {
170
+ errorMessage = promiseResult[0].reason.message;
171
+ } else {
172
+ errorMessage = __('An error occurred while permanently deleting the post.');
173
+ }
174
+ // If we were trying to permanently delete multiple posts
175
+ } else {
176
+ const errorMessages = new Set();
177
+ const failedPromises = promiseResult.filter(({
178
+ status
179
+ }) => status === 'rejected');
180
+ for (const failedPromise of failedPromises) {
181
+ if (failedPromise.reason?.message) {
182
+ errorMessages.add(failedPromise.reason.message);
183
+ }
184
+ }
185
+ if (errorMessages.size === 0) {
186
+ errorMessage = __('An error occurred while permanently deleting the posts.');
187
+ } else if (errorMessages.size === 1) {
188
+ errorMessage = sprintf( /* translators: %s: an error message */
189
+ __('An error occurred while permanently deleting the posts: %s'), [...errorMessages][0]);
190
+ } else {
191
+ errorMessage = sprintf( /* translators: %s: a list of comma separated error messages */
192
+ __('Some errors occurred while permanently deleting the posts: %s'), [...errorMessages].join(','));
193
+ }
194
+ createErrorNotice(errorMessage, {
195
+ type: 'snackbar'
196
+ });
197
+ }
198
+ }
199
+ }
200
+ }), [createSuccessNotice, createErrorNotice, deleteEntityRecord]);
201
+ }
202
+ export function useRestorePostAction() {
203
+ const {
204
+ createSuccessNotice,
205
+ createErrorNotice
206
+ } = useDispatch(noticesStore);
207
+ const {
208
+ editEntityRecord,
209
+ saveEditedEntityRecord
210
+ } = useDispatch(coreStore);
211
+ return useMemo(() => ({
212
+ id: 'restore',
213
+ label: __('Restore'),
214
+ isPrimary: true,
215
+ icon: backup,
216
+ supportsBulk: true,
217
+ isEligible({
218
+ status
219
+ }) {
220
+ return status === 'trash';
221
+ },
222
+ async callback(posts, onActionPerformed) {
223
+ try {
224
+ for (const post of posts) {
225
+ await editEntityRecord('postType', post.type, post.id, {
226
+ status: 'draft'
227
+ });
228
+ await saveEditedEntityRecord('postType', post.type, post.id, {
229
+ throwOnError: true
230
+ });
231
+ }
232
+ createSuccessNotice(posts.length > 1 ? sprintf( /* translators: The number of posts. */
233
+ __('%d posts have been restored.'), posts.length) : sprintf( /* translators: The number of posts. */
234
+ __('"%s" has been restored.'), getItemTitle(posts[0])), {
235
+ type: 'snackbar',
236
+ id: 'edit-site-post-restored'
237
+ });
238
+ if (onActionPerformed) {
239
+ onActionPerformed(posts);
240
+ }
241
+ } catch (error) {
242
+ let errorMessage;
243
+ if (error.message && error.code !== 'unknown_error' && error.message) {
244
+ errorMessage = error.message;
245
+ } else if (posts.length > 1) {
246
+ errorMessage = __('An error occurred while restoring the posts.');
247
+ } else {
248
+ errorMessage = __('An error occurred while restoring the post.');
249
+ }
250
+ createErrorNotice(errorMessage, {
251
+ type: 'snackbar'
252
+ });
253
+ }
254
+ }
255
+ }), [createSuccessNotice, createErrorNotice, editEntityRecord, saveEditedEntityRecord]);
256
+ }
257
+ export const viewPostAction = {
258
+ id: 'view-post',
259
+ label: __('View'),
260
+ isPrimary: true,
261
+ icon: external,
262
+ isEligible(post) {
263
+ return post.status !== 'trash';
264
+ },
265
+ callback(posts, onActionPerformed) {
266
+ const post = posts[0];
267
+ window.open(post.link, '_blank');
268
+ if (onActionPerformed) {
269
+ onActionPerformed(posts);
270
+ }
271
+ }
272
+ };
273
+ export const editPostAction = {
274
+ id: 'edit-post',
275
+ label: __('Edit'),
276
+ isPrimary: true,
277
+ icon: edit,
278
+ isEligible({
279
+ status
280
+ }) {
281
+ return status !== 'trash';
282
+ },
283
+ callback(posts, onActionPerformed) {
284
+ if (onActionPerformed) {
285
+ onActionPerformed(posts);
286
+ }
287
+ }
288
+ };
289
+ export const postRevisionsAction = {
290
+ id: 'view-post-revisions',
291
+ label: __('View revisions'),
292
+ isPrimary: false,
293
+ isEligible: post => {
294
+ var _post$_links$predeces, _post$_links$version;
295
+ if (post.status === 'trash') {
296
+ return false;
297
+ }
298
+ const lastRevisionId = (_post$_links$predeces = post?._links?.['predecessor-version']?.[0]?.id) !== null && _post$_links$predeces !== void 0 ? _post$_links$predeces : null;
299
+ const revisionsCount = (_post$_links$version = post?._links?.['version-history']?.[0]?.count) !== null && _post$_links$version !== void 0 ? _post$_links$version : 0;
300
+ return lastRevisionId && revisionsCount > 1;
301
+ },
302
+ callback(posts, onActionPerformed) {
303
+ const post = posts[0];
304
+ const href = addQueryArgs('revision.php', {
305
+ revision: post?._links?.['predecessor-version']?.[0]?.id
306
+ });
307
+ document.location.href = href;
308
+ if (onActionPerformed) {
309
+ onActionPerformed(posts);
310
+ }
311
+ }
312
+ };
313
+ export const renamePostAction = {
314
+ id: 'rename-post',
315
+ label: __('Rename'),
316
+ isEligible(post) {
317
+ return post.status !== 'trash';
318
+ },
319
+ RenderModal: ({
320
+ items,
321
+ closeModal
322
+ }) => {
323
+ const [item] = items;
324
+ const originalTitle = decodeEntities(typeof item.title === 'string' ? item.title : item.title.rendered);
325
+ const [title, setTitle] = useState(() => originalTitle);
326
+ const {
327
+ editEntityRecord,
328
+ saveEditedEntityRecord
329
+ } = useDispatch(coreStore);
330
+ const {
331
+ createSuccessNotice,
332
+ createErrorNotice
333
+ } = useDispatch(noticesStore);
334
+ async function onRename(event) {
335
+ event.preventDefault();
336
+ try {
337
+ await editEntityRecord('postType', item.type, item.id, {
338
+ title
339
+ });
340
+ // Update state before saving rerenders the list.
341
+ setTitle('');
342
+ closeModal();
343
+ // Persist edited entity.
344
+ await saveEditedEntityRecord('postType', item.type, item.id, {
345
+ throwOnError: true
346
+ });
347
+ createSuccessNotice(__('Name updated'), {
348
+ type: 'snackbar'
349
+ });
350
+ } catch (error) {
351
+ const errorMessage = error.message && error.code !== 'unknown_error' ? error.message : __('An error occurred while updating the name');
352
+ createErrorNotice(errorMessage, {
353
+ type: 'snackbar'
354
+ });
355
+ }
356
+ }
357
+ return createElement("form", {
358
+ onSubmit: onRename
359
+ }, createElement(VStack, {
360
+ spacing: "5"
361
+ }, createElement(TextControl, {
362
+ __nextHasNoMarginBottom: true,
363
+ __next40pxDefaultSize: true,
364
+ label: __('Name'),
365
+ value: title,
366
+ onChange: setTitle,
367
+ required: true
368
+ }), createElement(HStack, {
369
+ justify: "right"
370
+ }, createElement(Button, {
371
+ __next40pxDefaultSize: true,
372
+ variant: "tertiary",
373
+ onClick: () => {
374
+ closeModal();
375
+ }
376
+ }, __('Cancel')), createElement(Button, {
377
+ __next40pxDefaultSize: true,
378
+ variant: "primary",
379
+ type: "submit"
380
+ }, __('Save')))));
381
+ }
382
+ };
383
+ export function usePostActions(onActionPerformed, actionIds = null) {
384
+ const permanentlyDeletePostAction = usePermanentlyDeletePostAction();
385
+ const restorePostAction = useRestorePostAction();
386
+ return useMemo(() => {
387
+ // By default, return all actions...
388
+ const defaultActions = [editPostAction, viewPostAction, restorePostAction, permanentlyDeletePostAction, postRevisionsAction, renamePostAction, trashPostAction];
389
+
390
+ // ... unless `actionIds` was specified, in which case we find the
391
+ // actions matching the given IDs.
392
+ const actions = actionIds ? actionIds.map(actionId => defaultActions.find(({
393
+ id
394
+ }) => actionId === id)) : defaultActions;
395
+ if (onActionPerformed) {
396
+ for (let i = 0; i < actions.length; ++i) {
397
+ if (actions[i].callback) {
398
+ const existingCallback = actions[i].callback;
399
+ actions[i] = {
400
+ ...actions[i],
401
+ callback: (items, _onActionPerformed) => {
402
+ existingCallback(items, _items => {
403
+ if (_onActionPerformed) {
404
+ _onActionPerformed(_items);
405
+ }
406
+ onActionPerformed(actions[i].id, _items);
407
+ });
408
+ }
409
+ };
410
+ }
411
+ if (actions[i].RenderModal) {
412
+ const ExistingRenderModal = actions[i].RenderModal;
413
+ actions[i] = {
414
+ ...actions[i],
415
+ RenderModal: props => {
416
+ return createElement(ExistingRenderModal, {
417
+ items: props.items,
418
+ closeModal: props.closeModal,
419
+ onActionPerformed: _items => {
420
+ if (props.onActionPerformed) {
421
+ props.onActionPerformed(_items);
422
+ }
423
+ onActionPerformed(actions[i].id, _items);
424
+ }
425
+ });
426
+ }
427
+ };
428
+ }
429
+ }
430
+ }
431
+ return actions;
432
+ },
433
+ // Disable reason: if provided, `actionIds` is a shallow array of
434
+ // strings, and the strings themselves should be part of the useMemo
435
+ // dependencies. Two different disable statements are needed, as the
436
+ // first flags what it thinks are missing dependencies, and the second
437
+ // flags the array spread operation.
438
+ //
439
+ // eslint-disable-next-line react-hooks/exhaustive-deps
440
+ [
441
+ // eslint-disable-next-line react-hooks/exhaustive-deps
442
+ ...(actionIds || []), permanentlyDeletePostAction, restorePostAction, onActionPerformed]);
443
+ }
444
+ //# sourceMappingURL=actions.js.map