@wordpress/reusable-blocks 5.32.0 → 5.32.1-next.47f435fc9.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.
- package/build/components/index.js +36 -12
- package/build/components/index.js.map +7 -1
- package/build/components/reusable-blocks-menu-items/index.js +51 -34
- package/build/components/reusable-blocks-menu-items/index.js.map +7 -1
- package/build/components/reusable-blocks-menu-items/reusable-block-convert-button.js +189 -150
- package/build/components/reusable-blocks-menu-items/reusable-block-convert-button.js.map +7 -1
- package/build/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js +65 -72
- package/build/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js.map +7 -1
- package/build/index.js +27 -24
- package/build/index.js.map +7 -1
- package/build/lock-unlock.js +30 -14
- package/build/lock-unlock.js.map +7 -1
- package/build/store/actions.js +74 -81
- package/build/store/actions.js.map +7 -1
- package/build/store/index.js +44 -33
- package/build/store/index.js.map +7 -1
- package/build/store/reducer.js +30 -14
- package/build/store/reducer.js.map +7 -1
- package/build/store/selectors.js +26 -13
- package/build/store/selectors.js.map +7 -1
- package/build-module/components/index.js +5 -2
- package/build-module/components/index.js.map +7 -1
- package/build-module/components/reusable-blocks-menu-items/index.js +23 -27
- package/build-module/components/reusable-blocks-menu-items/index.js.map +7 -1
- package/build-module/components/reusable-blocks-menu-items/reusable-block-convert-button.js +178 -145
- package/build-module/components/reusable-blocks-menu-items/reusable-block-convert-button.js.map +7 -1
- package/build-module/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js +47 -66
- package/build-module/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js.map +7 -1
- package/build-module/index.js +6 -3
- package/build-module/index.js.map +7 -1
- package/build-module/lock-unlock.js +8 -7
- package/build-module/lock-unlock.js.map +7 -1
- package/build-module/store/actions.js +50 -68
- package/build-module/store/actions.js.map +7 -1
- package/build-module/store/index.js +10 -22
- package/build-module/store/index.js.map +7 -1
- package/build-module/store/reducer.js +9 -8
- package/build-module/store/reducer.js.map +7 -1
- package/build-module/store/selectors.js +5 -9
- package/build-module/store/selectors.js.map +7 -1
- package/build-style/style-rtl.css +3 -138
- package/build-style/style.css +3 -138
- package/package.json +21 -14
- package/src/components/reusable-blocks-menu-items/style.scss +2 -0
- package/src/style.scss +2 -1
- package/build/components/reusable-blocks-menu-items/index.native.js +0 -9
- package/build/components/reusable-blocks-menu-items/index.native.js.map +0 -1
- package/build/index.native.js +0 -29
- package/build/index.native.js.map +0 -1
- package/build-module/components/reusable-blocks-menu-items/index.native.js +0 -2
- package/build-module/components/reusable-blocks-menu-items/index.native.js.map +0 -1
- package/build-module/index.native.js +0 -7
- package/build-module/index.native.js.map +0 -1
package/build/store/reducer.js
CHANGED
|
@@ -1,17 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var reducer_exports = {};
|
|
19
|
+
__export(reducer_exports, {
|
|
20
|
+
default: () => reducer_default,
|
|
21
|
+
isEditingReusableBlock: () => isEditingReusableBlock
|
|
5
22
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
var _data = require("@wordpress/data");
|
|
9
|
-
/**
|
|
10
|
-
* WordPress dependencies
|
|
11
|
-
*/
|
|
12
|
-
|
|
23
|
+
module.exports = __toCommonJS(reducer_exports);
|
|
24
|
+
var import_data = require("@wordpress/data");
|
|
13
25
|
function isEditingReusableBlock(state = {}, action) {
|
|
14
|
-
if (action?.type ===
|
|
26
|
+
if (action?.type === "SET_EDITING_REUSABLE_BLOCK") {
|
|
15
27
|
return {
|
|
16
28
|
...state,
|
|
17
29
|
[action.clientId]: action.isEditing
|
|
@@ -19,7 +31,11 @@ function isEditingReusableBlock(state = {}, action) {
|
|
|
19
31
|
}
|
|
20
32
|
return state;
|
|
21
33
|
}
|
|
22
|
-
var
|
|
34
|
+
var reducer_default = (0, import_data.combineReducers)({
|
|
35
|
+
isEditingReusableBlock
|
|
36
|
+
});
|
|
37
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
38
|
+
0 && (module.exports = {
|
|
23
39
|
isEditingReusableBlock
|
|
24
40
|
});
|
|
25
|
-
//# sourceMappingURL=reducer.js.map
|
|
41
|
+
//# sourceMappingURL=reducer.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/store/reducer.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\n\nexport function isEditingReusableBlock( state = {}, action ) {\n\tif ( action?.type === 'SET_EDITING_REUSABLE_BLOCK' ) {\n\t\treturn {\n\t\t\t...state,\n\t\t\t[ action.clientId ]: action.isEditing,\n\t\t};\n\t}\n\n\treturn state;\n}\n\nexport default combineReducers( {\n\tisEditingReusableBlock,\n} );\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAgC;AAEzB,SAAS,uBAAwB,QAAQ,CAAC,GAAG,QAAS;AAC5D,MAAK,QAAQ,SAAS,8BAA+B;AACpD,WAAO;AAAA,MACN,GAAG;AAAA,MACH,CAAE,OAAO,QAAS,GAAG,OAAO;AAAA,IAC7B;AAAA,EACD;AAEA,SAAO;AACR;AAEA,IAAO,sBAAQ,6BAAiB;AAAA,EAC/B;AACD,CAAE;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build/store/selectors.js
CHANGED
|
@@ -1,17 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var selectors_exports = {};
|
|
19
|
+
__export(selectors_exports, {
|
|
20
|
+
__experimentalIsEditingReusableBlock: () => __experimentalIsEditingReusableBlock
|
|
5
21
|
});
|
|
6
|
-
exports
|
|
7
|
-
/**
|
|
8
|
-
* Returns true if reusable block is in the editing state.
|
|
9
|
-
*
|
|
10
|
-
* @param {Object} state Global application state.
|
|
11
|
-
* @param {number} clientId the clientID of the block.
|
|
12
|
-
* @return {boolean} Whether the reusable block is in the editing state.
|
|
13
|
-
*/
|
|
22
|
+
module.exports = __toCommonJS(selectors_exports);
|
|
14
23
|
function __experimentalIsEditingReusableBlock(state, clientId) {
|
|
15
24
|
return state.isEditingReusableBlock[clientId];
|
|
16
25
|
}
|
|
17
|
-
|
|
26
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
27
|
+
0 && (module.exports = {
|
|
28
|
+
__experimentalIsEditingReusableBlock
|
|
29
|
+
});
|
|
30
|
+
//# sourceMappingURL=selectors.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/store/selectors.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * Returns true if reusable block is in the editing state.\n *\n * @param {Object} state Global application state.\n * @param {number} clientId the clientID of the block.\n * @return {boolean} Whether the reusable block is in the editing state.\n */\nexport function __experimentalIsEditingReusableBlock( state, clientId ) {\n\treturn state.isEditingReusableBlock[ clientId ];\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOO,SAAS,qCAAsC,OAAO,UAAW;AACvE,SAAO,MAAM,uBAAwB,QAAS;AAC/C;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { default as default2 } from "./reusable-blocks-menu-items";
|
|
2
|
+
export {
|
|
3
|
+
default2 as ReusableBlocksMenuItems
|
|
4
|
+
};
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/components/index.js"],
|
|
4
|
+
"sourcesContent": ["export { default as ReusableBlocksMenuItems } from './reusable-blocks-menu-items';\n"],
|
|
5
|
+
"mappings": "AAAA,SAAoB,WAAXA,gBAA0C;",
|
|
6
|
+
"names": ["default"]
|
|
7
|
+
}
|
|
@@ -1,30 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import ReusableBlocksManageButton from './reusable-blocks-manage-button';
|
|
11
|
-
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
|
-
export default function ReusableBlocksMenuItems({
|
|
13
|
-
rootClientId
|
|
14
|
-
}) {
|
|
15
|
-
return /*#__PURE__*/_jsx(BlockSettingsMenuControls, {
|
|
16
|
-
children: ({
|
|
17
|
-
onClose,
|
|
18
|
-
selectedClientIds
|
|
19
|
-
}) => /*#__PURE__*/_jsxs(_Fragment, {
|
|
20
|
-
children: [/*#__PURE__*/_jsx(ReusableBlockConvertButton, {
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { BlockSettingsMenuControls } from "@wordpress/block-editor";
|
|
3
|
+
import ReusableBlockConvertButton from "./reusable-block-convert-button";
|
|
4
|
+
import ReusableBlocksManageButton from "./reusable-blocks-manage-button";
|
|
5
|
+
function ReusableBlocksMenuItems({ rootClientId }) {
|
|
6
|
+
return /* @__PURE__ */ jsx(BlockSettingsMenuControls, { children: ({ onClose, selectedClientIds }) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
7
|
+
/* @__PURE__ */ jsx(
|
|
8
|
+
ReusableBlockConvertButton,
|
|
9
|
+
{
|
|
21
10
|
clientIds: selectedClientIds,
|
|
22
|
-
rootClientId
|
|
23
|
-
onClose
|
|
24
|
-
}
|
|
11
|
+
rootClientId,
|
|
12
|
+
onClose
|
|
13
|
+
}
|
|
14
|
+
),
|
|
15
|
+
selectedClientIds.length === 1 && /* @__PURE__ */ jsx(
|
|
16
|
+
ReusableBlocksManageButton,
|
|
17
|
+
{
|
|
25
18
|
clientId: selectedClientIds[0]
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
});
|
|
19
|
+
}
|
|
20
|
+
)
|
|
21
|
+
] }) });
|
|
29
22
|
}
|
|
30
|
-
|
|
23
|
+
export {
|
|
24
|
+
ReusableBlocksMenuItems as default
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/reusable-blocks-menu-items/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { BlockSettingsMenuControls } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport ReusableBlockConvertButton from './reusable-block-convert-button';\nimport ReusableBlocksManageButton from './reusable-blocks-manage-button';\n\nexport default function ReusableBlocksMenuItems( { rootClientId } ) {\n\treturn (\n\t\t<BlockSettingsMenuControls>\n\t\t\t{ ( { onClose, selectedClientIds } ) => (\n\t\t\t\t<>\n\t\t\t\t\t<ReusableBlockConvertButton\n\t\t\t\t\t\tclientIds={ selectedClientIds }\n\t\t\t\t\t\trootClientId={ rootClientId }\n\t\t\t\t\t\tonClose={ onClose }\n\t\t\t\t\t/>\n\t\t\t\t\t{ selectedClientIds.length === 1 && (\n\t\t\t\t\t\t<ReusableBlocksManageButton\n\t\t\t\t\t\t\tclientId={ selectedClientIds[ 0 ] }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</>\n\t\t\t) }\n\t\t</BlockSettingsMenuControls>\n\t);\n}\n"],
|
|
5
|
+
"mappings": "AAeI,mBACC,KADD;AAZJ,SAAS,iCAAiC;AAK1C,OAAO,gCAAgC;AACvC,OAAO,gCAAgC;AAExB,SAAR,wBAA0C,EAAE,aAAa,GAAI;AACnE,SACC,oBAAC,6BACE,WAAE,EAAE,SAAS,kBAAkB,MAChC,iCACC;AAAA;AAAA,MAAC;AAAA;AAAA,QACA,WAAY;AAAA,QACZ;AAAA,QACA;AAAA;AAAA,IACD;AAAA,IACE,kBAAkB,WAAW,KAC9B;AAAA,MAAC;AAAA;AAAA,QACA,UAAW,kBAAmB,CAAE;AAAA;AAAA,IACjC;AAAA,KAEF,GAEF;AAEF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,156 +1,189 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
import { store } from
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
*
|
|
22
|
-
* @param {Object} props Component props.
|
|
23
|
-
* @param {string[]} props.clientIds Client ids of selected blocks.
|
|
24
|
-
* @param {string} props.rootClientId ID of the currently selected top-level block.
|
|
25
|
-
* @param {()=>void} props.onClose Callback to close the menu.
|
|
26
|
-
* @return {import('react').ComponentType} The menu control or null.
|
|
27
|
-
*/
|
|
28
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
29
|
-
export default function ReusableBlockConvertButton({
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { hasBlockSupport, isReusableBlock } from "@wordpress/blocks";
|
|
3
|
+
import { store as blockEditorStore } from "@wordpress/block-editor";
|
|
4
|
+
import { useCallback, useState } from "@wordpress/element";
|
|
5
|
+
import {
|
|
6
|
+
MenuItem,
|
|
7
|
+
Modal,
|
|
8
|
+
Button,
|
|
9
|
+
TextControl,
|
|
10
|
+
__experimentalHStack as HStack,
|
|
11
|
+
__experimentalVStack as VStack,
|
|
12
|
+
ToggleControl
|
|
13
|
+
} from "@wordpress/components";
|
|
14
|
+
import { symbol } from "@wordpress/icons";
|
|
15
|
+
import { useDispatch, useSelect } from "@wordpress/data";
|
|
16
|
+
import { __, _x, sprintf } from "@wordpress/i18n";
|
|
17
|
+
import { store as noticesStore } from "@wordpress/notices";
|
|
18
|
+
import { store as coreStore } from "@wordpress/core-data";
|
|
19
|
+
import { store } from "../../store";
|
|
20
|
+
function ReusableBlockConvertButton({
|
|
30
21
|
clientIds,
|
|
31
22
|
rootClientId,
|
|
32
23
|
onClose
|
|
33
24
|
}) {
|
|
34
|
-
const [syncType, setSyncType] = useState(
|
|
25
|
+
const [syncType, setSyncType] = useState(void 0);
|
|
35
26
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
36
|
-
const [title, setTitle] = useState(
|
|
37
|
-
const canConvert = useSelect(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
getBlockRootClientId
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
27
|
+
const [title, setTitle] = useState("");
|
|
28
|
+
const canConvert = useSelect(
|
|
29
|
+
(select) => {
|
|
30
|
+
const { canUser } = select(coreStore);
|
|
31
|
+
const {
|
|
32
|
+
getBlocksByClientId,
|
|
33
|
+
canInsertBlockType,
|
|
34
|
+
getBlockRootClientId
|
|
35
|
+
} = select(blockEditorStore);
|
|
36
|
+
const rootId = rootClientId || (clientIds.length > 0 ? getBlockRootClientId(clientIds[0]) : void 0);
|
|
37
|
+
const blocks = getBlocksByClientId(clientIds) ?? [];
|
|
38
|
+
const isReusable = blocks.length === 1 && blocks[0] && isReusableBlock(blocks[0]) && !!select(coreStore).getEntityRecord(
|
|
39
|
+
"postType",
|
|
40
|
+
"wp_block",
|
|
41
|
+
blocks[0].attributes.ref
|
|
42
|
+
);
|
|
43
|
+
const _canConvert = (
|
|
44
|
+
// Hide when this is already a reusable block.
|
|
45
|
+
!isReusable && // Hide when reusable blocks are disabled.
|
|
46
|
+
canInsertBlockType("core/block", rootId) && blocks.every(
|
|
47
|
+
(block) => (
|
|
48
|
+
// Guard against the case where a regular block has *just* been converted.
|
|
49
|
+
!!block && // Hide on invalid blocks.
|
|
50
|
+
block.isValid && // Hide when block doesn't support being made reusable.
|
|
51
|
+
hasBlockSupport(block.name, "reusable", true)
|
|
52
|
+
)
|
|
53
|
+
) && // Hide when current doesn't have permission to do that.
|
|
54
|
+
// Blocks refers to the wp_block post type, this checks the ability to create a post of that type.
|
|
55
|
+
!!canUser("create", {
|
|
56
|
+
kind: "postType",
|
|
57
|
+
name: "wp_block"
|
|
58
|
+
})
|
|
59
|
+
);
|
|
60
|
+
return _canConvert;
|
|
61
|
+
},
|
|
62
|
+
[clientIds, rootClientId]
|
|
63
|
+
);
|
|
64
|
+
const { __experimentalConvertBlocksToReusable: convertBlocksToReusable } = useDispatch(store);
|
|
65
|
+
const { createSuccessNotice, createErrorNotice } = useDispatch(noticesStore);
|
|
66
|
+
const onConvert = useCallback(
|
|
67
|
+
async function(reusableBlockTitle) {
|
|
68
|
+
try {
|
|
69
|
+
await convertBlocksToReusable(
|
|
70
|
+
clientIds,
|
|
71
|
+
reusableBlockTitle,
|
|
72
|
+
syncType
|
|
73
|
+
);
|
|
74
|
+
createSuccessNotice(
|
|
75
|
+
!syncType ? sprintf(
|
|
76
|
+
// translators: %s: the name the user has given to the pattern.
|
|
77
|
+
__("Synced pattern created: %s"),
|
|
78
|
+
reusableBlockTitle
|
|
79
|
+
) : sprintf(
|
|
80
|
+
// translators: %s: the name the user has given to the pattern.
|
|
81
|
+
__("Unsynced pattern created: %s"),
|
|
82
|
+
reusableBlockTitle
|
|
83
|
+
),
|
|
84
|
+
{
|
|
85
|
+
type: "snackbar",
|
|
86
|
+
id: "convert-to-reusable-block-success"
|
|
87
|
+
}
|
|
88
|
+
);
|
|
89
|
+
} catch (error) {
|
|
90
|
+
createErrorNotice(error.message, {
|
|
91
|
+
type: "snackbar",
|
|
92
|
+
id: "convert-to-reusable-block-error"
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
[
|
|
97
|
+
convertBlocksToReusable,
|
|
98
|
+
clientIds,
|
|
99
|
+
syncType,
|
|
100
|
+
createSuccessNotice,
|
|
101
|
+
createErrorNotice
|
|
102
|
+
]
|
|
103
|
+
);
|
|
94
104
|
if (!canConvert) {
|
|
95
105
|
return null;
|
|
96
106
|
}
|
|
97
|
-
return
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
onRequestClose: () => {
|
|
105
|
-
setIsModalOpen(false);
|
|
106
|
-
setTitle('');
|
|
107
|
-
},
|
|
108
|
-
overlayClassName: "reusable-blocks-menu-items__convert-modal",
|
|
109
|
-
children: /*#__PURE__*/_jsx("form", {
|
|
110
|
-
onSubmit: event => {
|
|
111
|
-
event.preventDefault();
|
|
112
|
-
onConvert(title);
|
|
107
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
108
|
+
/* @__PURE__ */ jsx(MenuItem, { icon: symbol, onClick: () => setIsModalOpen(true), children: __("Create pattern") }),
|
|
109
|
+
isModalOpen && /* @__PURE__ */ jsx(
|
|
110
|
+
Modal,
|
|
111
|
+
{
|
|
112
|
+
title: __("Create pattern"),
|
|
113
|
+
onRequestClose: () => {
|
|
113
114
|
setIsModalOpen(false);
|
|
114
|
-
setTitle(
|
|
115
|
-
onClose();
|
|
115
|
+
setTitle("");
|
|
116
116
|
},
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
117
|
+
overlayClassName: "reusable-blocks-menu-items__convert-modal",
|
|
118
|
+
children: /* @__PURE__ */ jsx(
|
|
119
|
+
"form",
|
|
120
|
+
{
|
|
121
|
+
onSubmit: (event) => {
|
|
122
|
+
event.preventDefault();
|
|
123
|
+
onConvert(title);
|
|
124
|
+
setIsModalOpen(false);
|
|
125
|
+
setTitle("");
|
|
126
|
+
onClose();
|
|
127
|
+
},
|
|
128
|
+
children: /* @__PURE__ */ jsxs(VStack, { spacing: "5", children: [
|
|
129
|
+
/* @__PURE__ */ jsx(
|
|
130
|
+
TextControl,
|
|
131
|
+
{
|
|
132
|
+
__next40pxDefaultSize: true,
|
|
133
|
+
__nextHasNoMarginBottom: true,
|
|
134
|
+
label: __("Name"),
|
|
135
|
+
value: title,
|
|
136
|
+
onChange: setTitle,
|
|
137
|
+
placeholder: __("My pattern")
|
|
138
|
+
}
|
|
139
|
+
),
|
|
140
|
+
/* @__PURE__ */ jsx(
|
|
141
|
+
ToggleControl,
|
|
142
|
+
{
|
|
143
|
+
__nextHasNoMarginBottom: true,
|
|
144
|
+
label: _x("Synced", "pattern (singular)"),
|
|
145
|
+
help: __(
|
|
146
|
+
"Sync this pattern across multiple locations."
|
|
147
|
+
),
|
|
148
|
+
checked: !syncType,
|
|
149
|
+
onChange: () => {
|
|
150
|
+
setSyncType(
|
|
151
|
+
!syncType ? "unsynced" : void 0
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
),
|
|
156
|
+
/* @__PURE__ */ jsxs(HStack, { justify: "right", children: [
|
|
157
|
+
/* @__PURE__ */ jsx(
|
|
158
|
+
Button,
|
|
159
|
+
{
|
|
160
|
+
__next40pxDefaultSize: true,
|
|
161
|
+
variant: "tertiary",
|
|
162
|
+
onClick: () => {
|
|
163
|
+
setIsModalOpen(false);
|
|
164
|
+
setTitle("");
|
|
165
|
+
},
|
|
166
|
+
children: __("Cancel")
|
|
167
|
+
}
|
|
168
|
+
),
|
|
169
|
+
/* @__PURE__ */ jsx(
|
|
170
|
+
Button,
|
|
171
|
+
{
|
|
172
|
+
__next40pxDefaultSize: true,
|
|
173
|
+
variant: "primary",
|
|
174
|
+
type: "submit",
|
|
175
|
+
children: __("Create")
|
|
176
|
+
}
|
|
177
|
+
)
|
|
178
|
+
] })
|
|
179
|
+
] })
|
|
180
|
+
}
|
|
181
|
+
)
|
|
182
|
+
}
|
|
183
|
+
)
|
|
184
|
+
] });
|
|
155
185
|
}
|
|
156
|
-
|
|
186
|
+
export {
|
|
187
|
+
ReusableBlockConvertButton as default
|
|
188
|
+
};
|
|
189
|
+
//# sourceMappingURL=reusable-block-convert-button.js.map
|
package/build-module/components/reusable-blocks-menu-items/reusable-block-convert-button.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{"version":3,"names":["hasBlockSupport","isReusableBlock","store","blockEditorStore","useCallback","useState","MenuItem","Modal","Button","TextControl","__experimentalHStack","HStack","__experimentalVStack","VStack","ToggleControl","symbol","useDispatch","useSelect","__","_x","sprintf","noticesStore","coreStore","jsx","_jsx","jsxs","_jsxs","Fragment","_Fragment","ReusableBlockConvertButton","clientIds","rootClientId","onClose","syncType","setSyncType","undefined","isModalOpen","setIsModalOpen","title","setTitle","canConvert","select","_getBlocksByClientId","canUser","getBlocksByClientId","canInsertBlockType","getBlockRootClientId","rootId","length","blocks","isReusable","getEntityRecord","attributes","ref","_canConvert","every","block","isValid","name","kind","__experimentalConvertBlocksToReusable","convertBlocksToReusable","createSuccessNotice","createErrorNotice","onConvert","reusableBlockTitle","type","id","error","message","children","icon","onClick","onRequestClose","overlayClassName","onSubmit","event","preventDefault","spacing","__next40pxDefaultSize","__nextHasNoMarginBottom","label","value","onChange","placeholder","help","checked","justify","variant"],"sources":["@wordpress/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-block-convert-button.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { hasBlockSupport, isReusableBlock } from '@wordpress/blocks';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { useCallback, useState } from '@wordpress/element';\nimport {\n\tMenuItem,\n\tModal,\n\tButton,\n\tTextControl,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n\tToggleControl,\n} from '@wordpress/components';\nimport { symbol } from '@wordpress/icons';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store } from '../../store';\n\n/**\n * Menu control to convert block(s) to reusable block.\n *\n * @param {Object} props Component props.\n * @param {string[]} props.clientIds Client ids of selected blocks.\n * @param {string} props.rootClientId ID of the currently selected top-level block.\n * @param {()=>void} props.onClose Callback to close the menu.\n * @return {import('react').ComponentType} The menu control or null.\n */\nexport default function ReusableBlockConvertButton( {\n\tclientIds,\n\trootClientId,\n\tonClose,\n} ) {\n\tconst [ syncType, setSyncType ] = useState( undefined );\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\tconst [ title, setTitle ] = useState( '' );\n\tconst canConvert = useSelect(\n\t\t( select ) => {\n\t\t\tconst { canUser } = select( coreStore );\n\t\t\tconst {\n\t\t\t\tgetBlocksByClientId,\n\t\t\t\tcanInsertBlockType,\n\t\t\t\tgetBlockRootClientId,\n\t\t\t} = select( blockEditorStore );\n\n\t\t\tconst rootId =\n\t\t\t\trootClientId ||\n\t\t\t\t( clientIds.length > 0\n\t\t\t\t\t? getBlockRootClientId( clientIds[ 0 ] )\n\t\t\t\t\t: undefined );\n\n\t\t\tconst blocks = getBlocksByClientId( clientIds ) ?? [];\n\n\t\t\tconst isReusable =\n\t\t\t\tblocks.length === 1 &&\n\t\t\t\tblocks[ 0 ] &&\n\t\t\t\tisReusableBlock( blocks[ 0 ] ) &&\n\t\t\t\t!! select( coreStore ).getEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'wp_block',\n\t\t\t\t\tblocks[ 0 ].attributes.ref\n\t\t\t\t);\n\n\t\t\tconst _canConvert =\n\t\t\t\t// Hide when this is already a reusable block.\n\t\t\t\t! isReusable &&\n\t\t\t\t// Hide when reusable blocks are disabled.\n\t\t\t\tcanInsertBlockType( 'core/block', rootId ) &&\n\t\t\t\tblocks.every(\n\t\t\t\t\t( block ) =>\n\t\t\t\t\t\t// Guard against the case where a regular block has *just* been converted.\n\t\t\t\t\t\t!! block &&\n\t\t\t\t\t\t// Hide on invalid blocks.\n\t\t\t\t\t\tblock.isValid &&\n\t\t\t\t\t\t// Hide when block doesn't support being made reusable.\n\t\t\t\t\t\thasBlockSupport( block.name, 'reusable', true )\n\t\t\t\t) &&\n\t\t\t\t// Hide when current doesn't have permission to do that.\n\t\t\t\t// Blocks refers to the wp_block post type, this checks the ability to create a post of that type.\n\t\t\t\t!! canUser( 'create', {\n\t\t\t\t\tkind: 'postType',\n\t\t\t\t\tname: 'wp_block',\n\t\t\t\t} );\n\n\t\t\treturn _canConvert;\n\t\t},\n\t\t[ clientIds, rootClientId ]\n\t);\n\n\tconst { __experimentalConvertBlocksToReusable: convertBlocksToReusable } =\n\t\tuseDispatch( store );\n\n\tconst { createSuccessNotice, createErrorNotice } =\n\t\tuseDispatch( noticesStore );\n\tconst onConvert = useCallback(\n\t\tasync function ( reusableBlockTitle ) {\n\t\t\ttry {\n\t\t\t\tawait convertBlocksToReusable(\n\t\t\t\t\tclientIds,\n\t\t\t\t\treusableBlockTitle,\n\t\t\t\t\tsyncType\n\t\t\t\t);\n\t\t\t\tcreateSuccessNotice(\n\t\t\t\t\t! syncType\n\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t// translators: %s: the name the user has given to the pattern.\n\t\t\t\t\t\t\t\t__( 'Synced pattern created: %s' ),\n\t\t\t\t\t\t\t\treusableBlockTitle\n\t\t\t\t\t\t )\n\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t// translators: %s: the name the user has given to the pattern.\n\t\t\t\t\t\t\t\t__( 'Unsynced pattern created: %s' ),\n\t\t\t\t\t\t\t\treusableBlockTitle\n\t\t\t\t\t\t ),\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\tid: 'convert-to-reusable-block-success',\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t} catch ( error ) {\n\t\t\t\tcreateErrorNotice( error.message, {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tid: 'convert-to-reusable-block-error',\n\t\t\t\t} );\n\t\t\t}\n\t\t},\n\t\t[\n\t\t\tconvertBlocksToReusable,\n\t\t\tclientIds,\n\t\t\tsyncType,\n\t\t\tcreateSuccessNotice,\n\t\t\tcreateErrorNotice,\n\t\t]\n\t);\n\n\tif ( ! canConvert ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<MenuItem icon={ symbol } onClick={ () => setIsModalOpen( true ) }>\n\t\t\t\t{ __( 'Create pattern' ) }\n\t\t\t</MenuItem>\n\t\t\t{ isModalOpen && (\n\t\t\t\t<Modal\n\t\t\t\t\ttitle={ __( 'Create pattern' ) }\n\t\t\t\t\tonRequestClose={ () => {\n\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t} }\n\t\t\t\t\toverlayClassName=\"reusable-blocks-menu-items__convert-modal\"\n\t\t\t\t>\n\t\t\t\t\t<form\n\t\t\t\t\t\tonSubmit={ ( event ) => {\n\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t\tonConvert( title );\n\t\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t<VStack spacing=\"5\">\n\t\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\t\t\tplaceholder={ __( 'My pattern' ) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\t\tlabel={ _x( 'Synced', 'pattern (singular)' ) }\n\t\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t\t'Sync this pattern across multiple locations.'\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\tchecked={ ! syncType }\n\t\t\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\t\t\tsetSyncType(\n\t\t\t\t\t\t\t\t\t\t! syncType ? 'unsynced' : undefined\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t\t\t</Button>\n\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Create' ) }\n\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t</HStack>\n\t\t\t\t\t\t</VStack>\n\t\t\t\t\t</form>\n\t\t\t\t</Modal>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,eAAe,EAAEC,eAAe,QAAQ,mBAAmB;AACpE,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,yBAAyB;AACnE,SAASC,WAAW,EAAEC,QAAQ,QAAQ,oBAAoB;AAC1D,SACCC,QAAQ,EACRC,KAAK,EACLC,MAAM,EACNC,WAAW,EACXC,oBAAoB,IAAIC,MAAM,EAC9BC,oBAAoB,IAAIC,MAAM,EAC9BC,aAAa,QACP,uBAAuB;AAC9B,SAASC,MAAM,QAAQ,kBAAkB;AACzC,SAASC,WAAW,EAAEC,SAAS,QAAQ,iBAAiB;AACxD,SAASC,EAAE,EAAEC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AACjD,SAASlB,KAAK,IAAImB,YAA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YACbkE,uBAAuB;YACvBC,KAAK,EAAG9D,EAAE,CAAE,QAAQ,EAAE,oBAAqB,CAAG;YAC9CkE,IAAI,EAAGnE,EAAE,CACR,8CACD,CAAG;YACHoE,OAAO,EAAG,CAAErD,QAAU;YACtBkD,QAAQ,EAAGA,CAAA,KAAM;cAChBjD,WAAW,CACV,CAAED,QAAQ,GAAG,UAAU,GAAGE,SAC3B,CAAC;YACF;UAAG,CACH,CAAC,eACFT,KAAA,CAACf,MAAM;YAAC4E,OAAO,EAAC,OAAO;YAAAjB,QAAA,gBACtB9C,IAAA,CAAChB,MAAM;cACNuE,qBAAqB;cACrBS,OAAO,EAAC,UAAU;cAClBhB,OAAO,EAAGA,CAAA,KAAM;gBACfnC,cAAc,CAAE,KAAM,CAAC;gBACvBE,QAAQ,CAAE,EAAG,CAAC;cACf,CAAG;cAAA+B,QAAA,EAEDpD,EAAE,CAAE,QAAS;YAAC,CACT,CAAC,eAETM,IAAA,CAAChB,MAAM;cACNuE,qBAAqB;cACrBS,OAAO,EAAC,SAAS;cACjBtB,IAAI,EAAC,QAAQ;cAAAI,QAAA,EAEXpD,EAAE,CAAE,QAAS;YAAC,CACT,CAAC;UAAA,CACF,CAAC;QAAA,CACF;MAAC,CACJ;IAAC,CACD,CACP;EAAA,CACA,CAAC;AAEL","ignoreList":[]}
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/reusable-blocks-menu-items/reusable-block-convert-button.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { hasBlockSupport, isReusableBlock } from '@wordpress/blocks';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { useCallback, useState } from '@wordpress/element';\nimport {\n\tMenuItem,\n\tModal,\n\tButton,\n\tTextControl,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n\tToggleControl,\n} from '@wordpress/components';\nimport { symbol } from '@wordpress/icons';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store } from '../../store';\n\n/**\n * Menu control to convert block(s) to reusable block.\n *\n * @param {Object} props Component props.\n * @param {string[]} props.clientIds Client ids of selected blocks.\n * @param {string} props.rootClientId ID of the currently selected top-level block.\n * @param {()=>void} props.onClose Callback to close the menu.\n * @return {import('react').ComponentType} The menu control or null.\n */\nexport default function ReusableBlockConvertButton( {\n\tclientIds,\n\trootClientId,\n\tonClose,\n} ) {\n\tconst [ syncType, setSyncType ] = useState( undefined );\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\tconst [ title, setTitle ] = useState( '' );\n\tconst canConvert = useSelect(\n\t\t( select ) => {\n\t\t\tconst { canUser } = select( coreStore );\n\t\t\tconst {\n\t\t\t\tgetBlocksByClientId,\n\t\t\t\tcanInsertBlockType,\n\t\t\t\tgetBlockRootClientId,\n\t\t\t} = select( blockEditorStore );\n\n\t\t\tconst rootId =\n\t\t\t\trootClientId ||\n\t\t\t\t( clientIds.length > 0\n\t\t\t\t\t? getBlockRootClientId( clientIds[ 0 ] )\n\t\t\t\t\t: undefined );\n\n\t\t\tconst blocks = getBlocksByClientId( clientIds ) ?? [];\n\n\t\t\tconst isReusable =\n\t\t\t\tblocks.length === 1 &&\n\t\t\t\tblocks[ 0 ] &&\n\t\t\t\tisReusableBlock( blocks[ 0 ] ) &&\n\t\t\t\t!! select( coreStore ).getEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'wp_block',\n\t\t\t\t\tblocks[ 0 ].attributes.ref\n\t\t\t\t);\n\n\t\t\tconst _canConvert =\n\t\t\t\t// Hide when this is already a reusable block.\n\t\t\t\t! isReusable &&\n\t\t\t\t// Hide when reusable blocks are disabled.\n\t\t\t\tcanInsertBlockType( 'core/block', rootId ) &&\n\t\t\t\tblocks.every(\n\t\t\t\t\t( block ) =>\n\t\t\t\t\t\t// Guard against the case where a regular block has *just* been converted.\n\t\t\t\t\t\t!! block &&\n\t\t\t\t\t\t// Hide on invalid blocks.\n\t\t\t\t\t\tblock.isValid &&\n\t\t\t\t\t\t// Hide when block doesn't support being made reusable.\n\t\t\t\t\t\thasBlockSupport( block.name, 'reusable', true )\n\t\t\t\t) &&\n\t\t\t\t// Hide when current doesn't have permission to do that.\n\t\t\t\t// Blocks refers to the wp_block post type, this checks the ability to create a post of that type.\n\t\t\t\t!! canUser( 'create', {\n\t\t\t\t\tkind: 'postType',\n\t\t\t\t\tname: 'wp_block',\n\t\t\t\t} );\n\n\t\t\treturn _canConvert;\n\t\t},\n\t\t[ clientIds, rootClientId ]\n\t);\n\n\tconst { __experimentalConvertBlocksToReusable: convertBlocksToReusable } =\n\t\tuseDispatch( store );\n\n\tconst { createSuccessNotice, createErrorNotice } =\n\t\tuseDispatch( noticesStore );\n\tconst onConvert = useCallback(\n\t\tasync function ( reusableBlockTitle ) {\n\t\t\ttry {\n\t\t\t\tawait convertBlocksToReusable(\n\t\t\t\t\tclientIds,\n\t\t\t\t\treusableBlockTitle,\n\t\t\t\t\tsyncType\n\t\t\t\t);\n\t\t\t\tcreateSuccessNotice(\n\t\t\t\t\t! syncType\n\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t// translators: %s: the name the user has given to the pattern.\n\t\t\t\t\t\t\t\t__( 'Synced pattern created: %s' ),\n\t\t\t\t\t\t\t\treusableBlockTitle\n\t\t\t\t\t\t )\n\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t// translators: %s: the name the user has given to the pattern.\n\t\t\t\t\t\t\t\t__( 'Unsynced pattern created: %s' ),\n\t\t\t\t\t\t\t\treusableBlockTitle\n\t\t\t\t\t\t ),\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\tid: 'convert-to-reusable-block-success',\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t} catch ( error ) {\n\t\t\t\tcreateErrorNotice( error.message, {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tid: 'convert-to-reusable-block-error',\n\t\t\t\t} );\n\t\t\t}\n\t\t},\n\t\t[\n\t\t\tconvertBlocksToReusable,\n\t\t\tclientIds,\n\t\t\tsyncType,\n\t\t\tcreateSuccessNotice,\n\t\t\tcreateErrorNotice,\n\t\t]\n\t);\n\n\tif ( ! canConvert ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<MenuItem icon={ symbol } onClick={ () => setIsModalOpen( true ) }>\n\t\t\t\t{ __( 'Create pattern' ) }\n\t\t\t</MenuItem>\n\t\t\t{ isModalOpen && (\n\t\t\t\t<Modal\n\t\t\t\t\ttitle={ __( 'Create pattern' ) }\n\t\t\t\t\tonRequestClose={ () => {\n\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t} }\n\t\t\t\t\toverlayClassName=\"reusable-blocks-menu-items__convert-modal\"\n\t\t\t\t>\n\t\t\t\t\t<form\n\t\t\t\t\t\tonSubmit={ ( event ) => {\n\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t\tonConvert( title );\n\t\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t<VStack spacing=\"5\">\n\t\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\t\t\tplaceholder={ __( 'My pattern' ) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\t\tlabel={ _x( 'Synced', 'pattern (singular)' ) }\n\t\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t\t'Sync this pattern across multiple locations.'\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\tchecked={ ! syncType }\n\t\t\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\t\t\tsetSyncType(\n\t\t\t\t\t\t\t\t\t\t! syncType ? 'unsynced' : undefined\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t\t\t</Button>\n\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Create' ) }\n\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t</HStack>\n\t\t\t\t\t\t</VStack>\n\t\t\t\t\t</form>\n\t\t\t\t</Modal>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"],
|
|
5
|
+
"mappings": "AAmJE,mBACC,KA2CI,YA5CL;AAhJF,SAAS,iBAAiB,uBAAuB;AACjD,SAAS,SAAS,wBAAwB;AAC1C,SAAS,aAAa,gBAAgB;AACtC;AAAA,EACC;AAA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