@wordpress/reusable-blocks 5.32.0 → 5.32.1-next.ff1cebbba.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
|
@@ -1,14 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
Object.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
16
|
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var components_exports = {};
|
|
29
|
+
__export(components_exports, {
|
|
30
|
+
ReusableBlocksMenuItems: () => import_reusable_blocks_menu_items.default
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(components_exports);
|
|
33
|
+
var import_reusable_blocks_menu_items = __toESM(require("./reusable-blocks-menu-items"));
|
|
34
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
35
|
+
0 && (module.exports = {
|
|
36
|
+
ReusableBlocksMenuItems
|
|
12
37
|
});
|
|
13
|
-
|
|
14
|
-
//# sourceMappingURL=index.js.map
|
|
38
|
+
//# 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;AAAA;AAAA;AAAA;AAAA;AAAA,wCAAmD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,38 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
Object.
|
|
5
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var reusable_blocks_menu_items_exports = {};
|
|
29
|
+
__export(reusable_blocks_menu_items_exports, {
|
|
30
|
+
default: () => ReusableBlocksMenuItems
|
|
6
31
|
});
|
|
7
|
-
exports
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* Internal dependencies
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
function ReusableBlocksMenuItems({
|
|
21
|
-
rootClientId
|
|
22
|
-
}) {
|
|
23
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.BlockSettingsMenuControls, {
|
|
24
|
-
children: ({
|
|
25
|
-
onClose,
|
|
26
|
-
selectedClientIds
|
|
27
|
-
}) => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
28
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reusableBlockConvertButton.default, {
|
|
32
|
+
module.exports = __toCommonJS(reusable_blocks_menu_items_exports);
|
|
33
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
34
|
+
var import_block_editor = require("@wordpress/block-editor");
|
|
35
|
+
var import_reusable_block_convert_button = __toESM(require("./reusable-block-convert-button"));
|
|
36
|
+
var import_reusable_blocks_manage_button = __toESM(require("./reusable-blocks-manage-button"));
|
|
37
|
+
function ReusableBlocksMenuItems({ rootClientId }) {
|
|
38
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_block_editor.BlockSettingsMenuControls, { children: ({ onClose, selectedClientIds }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
39
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
40
|
+
import_reusable_block_convert_button.default,
|
|
41
|
+
{
|
|
29
42
|
clientIds: selectedClientIds,
|
|
30
|
-
rootClientId
|
|
31
|
-
onClose
|
|
32
|
-
}
|
|
43
|
+
rootClientId,
|
|
44
|
+
onClose
|
|
45
|
+
}
|
|
46
|
+
),
|
|
47
|
+
selectedClientIds.length === 1 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
48
|
+
import_reusable_blocks_manage_button.default,
|
|
49
|
+
{
|
|
33
50
|
clientId: selectedClientIds[0]
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
});
|
|
51
|
+
}
|
|
52
|
+
)
|
|
53
|
+
] }) });
|
|
37
54
|
}
|
|
38
|
-
//# sourceMappingURL=index.js.map
|
|
55
|
+
//# 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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAeI;AAZJ,0BAA0C;AAK1C,2CAAuC;AACvC,2CAAuC;AAExB,SAAR,wBAA0C,EAAE,aAAa,GAAI;AACnE,SACC,4CAAC,iDACE,WAAE,EAAE,SAAS,kBAAkB,MAChC,4EACC;AAAA;AAAA,MAAC,qCAAAA;AAAA,MAAA;AAAA,QACA,WAAY;AAAA,QACZ;AAAA,QACA;AAAA;AAAA,IACD;AAAA,IACE,kBAAkB,WAAW,KAC9B;AAAA,MAAC,qCAAAC;AAAA,MAAA;AAAA,QACA,UAAW,kBAAmB,CAAE;AAAA;AAAA,IACjC;AAAA,KAEF,GAEF;AAEF;",
|
|
6
|
+
"names": ["ReusableBlockConvertButton", "ReusableBlocksManageButton"]
|
|
7
|
+
}
|
|
@@ -1,161 +1,200 @@
|
|
|
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 reusable_block_convert_button_exports = {};
|
|
19
|
+
__export(reusable_block_convert_button_exports, {
|
|
20
|
+
default: () => ReusableBlockConvertButton
|
|
5
21
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
var
|
|
15
|
-
var
|
|
16
|
-
var
|
|
17
|
-
var
|
|
18
|
-
|
|
19
|
-
* WordPress dependencies
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Internal dependencies
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Menu control to convert block(s) to reusable block.
|
|
28
|
-
*
|
|
29
|
-
* @param {Object} props Component props.
|
|
30
|
-
* @param {string[]} props.clientIds Client ids of selected blocks.
|
|
31
|
-
* @param {string} props.rootClientId ID of the currently selected top-level block.
|
|
32
|
-
* @param {()=>void} props.onClose Callback to close the menu.
|
|
33
|
-
* @return {import('react').ComponentType} The menu control or null.
|
|
34
|
-
*/function ReusableBlockConvertButton({
|
|
22
|
+
module.exports = __toCommonJS(reusable_block_convert_button_exports);
|
|
23
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
24
|
+
var import_blocks = require("@wordpress/blocks");
|
|
25
|
+
var import_block_editor = require("@wordpress/block-editor");
|
|
26
|
+
var import_element = require("@wordpress/element");
|
|
27
|
+
var import_components = require("@wordpress/components");
|
|
28
|
+
var import_icons = require("@wordpress/icons");
|
|
29
|
+
var import_data = require("@wordpress/data");
|
|
30
|
+
var import_i18n = require("@wordpress/i18n");
|
|
31
|
+
var import_notices = require("@wordpress/notices");
|
|
32
|
+
var import_core_data = require("@wordpress/core-data");
|
|
33
|
+
var import_store = require("../../store");
|
|
34
|
+
function ReusableBlockConvertButton({
|
|
35
35
|
clientIds,
|
|
36
36
|
rootClientId,
|
|
37
37
|
onClose
|
|
38
38
|
}) {
|
|
39
|
-
const [syncType, setSyncType] = (0,
|
|
40
|
-
const [isModalOpen, setIsModalOpen] = (0,
|
|
41
|
-
const [title, setTitle] = (0,
|
|
42
|
-
const canConvert = (0,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
getBlockRootClientId
|
|
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
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
39
|
+
const [syncType, setSyncType] = (0, import_element.useState)(void 0);
|
|
40
|
+
const [isModalOpen, setIsModalOpen] = (0, import_element.useState)(false);
|
|
41
|
+
const [title, setTitle] = (0, import_element.useState)("");
|
|
42
|
+
const canConvert = (0, import_data.useSelect)(
|
|
43
|
+
(select) => {
|
|
44
|
+
const { canUser } = select(import_core_data.store);
|
|
45
|
+
const {
|
|
46
|
+
getBlocksByClientId,
|
|
47
|
+
canInsertBlockType,
|
|
48
|
+
getBlockRootClientId
|
|
49
|
+
} = select(import_block_editor.store);
|
|
50
|
+
const rootId = rootClientId || (clientIds.length > 0 ? getBlockRootClientId(clientIds[0]) : void 0);
|
|
51
|
+
const blocks = getBlocksByClientId(clientIds) ?? [];
|
|
52
|
+
const isReusable = blocks.length === 1 && blocks[0] && (0, import_blocks.isReusableBlock)(blocks[0]) && !!select(import_core_data.store).getEntityRecord(
|
|
53
|
+
"postType",
|
|
54
|
+
"wp_block",
|
|
55
|
+
blocks[0].attributes.ref
|
|
56
|
+
);
|
|
57
|
+
const _canConvert = (
|
|
58
|
+
// Hide when this is already a reusable block.
|
|
59
|
+
!isReusable && // Hide when reusable blocks are disabled.
|
|
60
|
+
canInsertBlockType("core/block", rootId) && blocks.every(
|
|
61
|
+
(block) => (
|
|
62
|
+
// Guard against the case where a regular block has *just* been converted.
|
|
63
|
+
!!block && // Hide on invalid blocks.
|
|
64
|
+
block.isValid && // Hide when block doesn't support being made reusable.
|
|
65
|
+
(0, import_blocks.hasBlockSupport)(block.name, "reusable", true)
|
|
66
|
+
)
|
|
67
|
+
) && // Hide when current doesn't have permission to do that.
|
|
68
|
+
// Blocks refers to the wp_block post type, this checks the ability to create a post of that type.
|
|
69
|
+
!!canUser("create", {
|
|
70
|
+
kind: "postType",
|
|
71
|
+
name: "wp_block"
|
|
72
|
+
})
|
|
73
|
+
);
|
|
74
|
+
return _canConvert;
|
|
75
|
+
},
|
|
76
|
+
[clientIds, rootClientId]
|
|
77
|
+
);
|
|
78
|
+
const { __experimentalConvertBlocksToReusable: convertBlocksToReusable } = (0, import_data.useDispatch)(import_store.store);
|
|
79
|
+
const { createSuccessNotice, createErrorNotice } = (0, import_data.useDispatch)(import_notices.store);
|
|
80
|
+
const onConvert = (0, import_element.useCallback)(
|
|
81
|
+
async function(reusableBlockTitle) {
|
|
82
|
+
try {
|
|
83
|
+
await convertBlocksToReusable(
|
|
84
|
+
clientIds,
|
|
85
|
+
reusableBlockTitle,
|
|
86
|
+
syncType
|
|
87
|
+
);
|
|
88
|
+
createSuccessNotice(
|
|
89
|
+
!syncType ? (0, import_i18n.sprintf)(
|
|
90
|
+
// translators: %s: the name the user has given to the pattern.
|
|
91
|
+
(0, import_i18n.__)("Synced pattern created: %s"),
|
|
92
|
+
reusableBlockTitle
|
|
93
|
+
) : (0, import_i18n.sprintf)(
|
|
94
|
+
// translators: %s: the name the user has given to the pattern.
|
|
95
|
+
(0, import_i18n.__)("Unsynced pattern created: %s"),
|
|
96
|
+
reusableBlockTitle
|
|
97
|
+
),
|
|
98
|
+
{
|
|
99
|
+
type: "snackbar",
|
|
100
|
+
id: "convert-to-reusable-block-success"
|
|
101
|
+
}
|
|
102
|
+
);
|
|
103
|
+
} catch (error) {
|
|
104
|
+
createErrorNotice(error.message, {
|
|
105
|
+
type: "snackbar",
|
|
106
|
+
id: "convert-to-reusable-block-error"
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
[
|
|
111
|
+
convertBlocksToReusable,
|
|
112
|
+
clientIds,
|
|
113
|
+
syncType,
|
|
114
|
+
createSuccessNotice,
|
|
115
|
+
createErrorNotice
|
|
116
|
+
]
|
|
117
|
+
);
|
|
99
118
|
if (!canConvert) {
|
|
100
119
|
return null;
|
|
101
120
|
}
|
|
102
|
-
return
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
onRequestClose: () => {
|
|
110
|
-
setIsModalOpen(false);
|
|
111
|
-
setTitle('');
|
|
112
|
-
},
|
|
113
|
-
overlayClassName: "reusable-blocks-menu-items__convert-modal",
|
|
114
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("form", {
|
|
115
|
-
onSubmit: event => {
|
|
116
|
-
event.preventDefault();
|
|
117
|
-
onConvert(title);
|
|
121
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
122
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.MenuItem, { icon: import_icons.symbol, onClick: () => setIsModalOpen(true), children: (0, import_i18n.__)("Create pattern") }),
|
|
123
|
+
isModalOpen && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
124
|
+
import_components.Modal,
|
|
125
|
+
{
|
|
126
|
+
title: (0, import_i18n.__)("Create pattern"),
|
|
127
|
+
onRequestClose: () => {
|
|
118
128
|
setIsModalOpen(false);
|
|
119
|
-
setTitle(
|
|
120
|
-
onClose();
|
|
129
|
+
setTitle("");
|
|
121
130
|
},
|
|
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
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
131
|
+
overlayClassName: "reusable-blocks-menu-items__convert-modal",
|
|
132
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
133
|
+
"form",
|
|
134
|
+
{
|
|
135
|
+
onSubmit: (event) => {
|
|
136
|
+
event.preventDefault();
|
|
137
|
+
onConvert(title);
|
|
138
|
+
setIsModalOpen(false);
|
|
139
|
+
setTitle("");
|
|
140
|
+
onClose();
|
|
141
|
+
},
|
|
142
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalVStack, { spacing: "5", children: [
|
|
143
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
144
|
+
import_components.TextControl,
|
|
145
|
+
{
|
|
146
|
+
__next40pxDefaultSize: true,
|
|
147
|
+
__nextHasNoMarginBottom: true,
|
|
148
|
+
label: (0, import_i18n.__)("Name"),
|
|
149
|
+
value: title,
|
|
150
|
+
onChange: setTitle,
|
|
151
|
+
placeholder: (0, import_i18n.__)("My pattern")
|
|
152
|
+
}
|
|
153
|
+
),
|
|
154
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
155
|
+
import_components.ToggleControl,
|
|
156
|
+
{
|
|
157
|
+
__nextHasNoMarginBottom: true,
|
|
158
|
+
label: (0, import_i18n._x)("Synced", "pattern (singular)"),
|
|
159
|
+
help: (0, import_i18n.__)(
|
|
160
|
+
"Sync this pattern across multiple locations."
|
|
161
|
+
),
|
|
162
|
+
checked: !syncType,
|
|
163
|
+
onChange: () => {
|
|
164
|
+
setSyncType(
|
|
165
|
+
!syncType ? "unsynced" : void 0
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
),
|
|
170
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalHStack, { justify: "right", children: [
|
|
171
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
172
|
+
import_components.Button,
|
|
173
|
+
{
|
|
174
|
+
__next40pxDefaultSize: true,
|
|
175
|
+
variant: "tertiary",
|
|
176
|
+
onClick: () => {
|
|
177
|
+
setIsModalOpen(false);
|
|
178
|
+
setTitle("");
|
|
179
|
+
},
|
|
180
|
+
children: (0, import_i18n.__)("Cancel")
|
|
181
|
+
}
|
|
182
|
+
),
|
|
183
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
184
|
+
import_components.Button,
|
|
185
|
+
{
|
|
186
|
+
__next40pxDefaultSize: true,
|
|
187
|
+
variant: "primary",
|
|
188
|
+
type: "submit",
|
|
189
|
+
children: (0, import_i18n.__)("Create")
|
|
190
|
+
}
|
|
191
|
+
)
|
|
192
|
+
] })
|
|
193
|
+
] })
|
|
194
|
+
}
|
|
195
|
+
)
|
|
196
|
+
}
|
|
197
|
+
)
|
|
198
|
+
] });
|
|
160
199
|
}
|
|
161
|
-
//# sourceMappingURL=reusable-block-convert-button.js.map
|
|
200
|
+
//# sourceMappingURL=reusable-block-convert-button.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{"version":3,"names":["_blocks","require","_blockEditor","_element","_components","_icons","_data","_i18n","_notices","_coreData","_store","_jsxRuntime","ReusableBlockConvertButton","clientIds","rootClientId","onClose","syncType","setSyncType","useState","undefined","isModalOpen","setIsModalOpen","title","setTitle","canConvert","useSelect","select","_getBlocksByClientId","canUser","coreStore","getBlocksByClientId","canInsertBlockType","getBlockRootClientId","blockEditorStore","rootId","length","blocks","isReusable","isReusableBlock","getEntityRecord","attributes","ref","_canConvert","every","block","isValid","hasBlockSupport","name","kind","__experimentalConvertBlocksToReusable","convertBlocksToReusable","useDispatch","store","createSuccessNotice","createErrorNotice","noticesStore","onConvert","useCallback","reusableBlockTitle","sprintf","__","type","id","error","message","jsxs","Fragment","children","jsx","MenuItem","icon","symbol","onClick","Modal","onRequestClose","overlayClassName","onSubmit","event","preventDefault","__experimentalVStack","spacing","TextControl","__next40pxDefaultSize","__nextHasNoMarginBottom","label","value","onChange","placeholder","ToggleControl","_x","help","checked","__experimentalHStack","justify","Button","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":";;;;;;AAGA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AASA,IAAAI,MAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAL,OAAA;AACA,IAAAM,KAAA,GAAAN,OAAA;AACA,IAAAO,QAAA,GAAAP,OAAA;AACA,IAAAQ,SAAA,GAAAR,OAAA;AAKA,IAAAS,MAAA,GAAAT,OAAA;AAAoC,IAAAU,WAAA,GAAAV,OAAA;AAxBpC;AACA;AACA;;AAmBA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACe,SAASW,0BAA0BA,CAAE;EACnDC,SAAS;EACTC,YAAY;EACZC;AACD,CAAC,EAAG;EACH,MAAM,CAAEC,QAAQ,EAAEC,WAAW,CAAE,GAAG,IAAAC,iBAAQ,EAAEC,SAAU,CAAC;EACvD,MAAM,CAAEC,WAAW,EAAEC,cAAc,CAAE,GAAG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QAAU;YACtBsE,QAAQ,EAAGA,CAAA,KAAM;cAChBrE,WAAW,CACV,CAAED,QAAQ,GAAG,UAAU,GAAGG,SAC3B,CAAC;YACF;UAAG,CACH,CAAC,eACF,IAAAR,WAAA,CAAAsD,IAAA,EAAC7D,WAAA,CAAAwF,oBAAM;YAACC,OAAO,EAAC,OAAO;YAAA1B,QAAA,gBACtB,IAAAxD,WAAA,CAAAyD,GAAA,EAAChE,WAAA,CAAA0F,MAAM;cACNZ,qBAAqB;cACrBa,OAAO,EAAC,UAAU;cAClBvB,OAAO,EAAGA,CAAA,KAAM;gBACfnD,cAAc,CAAE,KAAM,CAAC;gBACvBE,QAAQ,CAAE,EAAG,CAAC;cACf,CAAG;cAAA4C,QAAA,EAED,IAAAP,QAAE,EAAE,QAAS;YAAC,CACT,CAAC,eAET,IAAAjD,WAAA,CAAAyD,GAAA,EAAChE,WAAA,CAAA0F,MAAM;cACNZ,qBAAqB;cACrBa,OAAO,EAAC,SAAS;cACjBlC,IAAI,EAAC,QAAQ;cAAAM,QAAA,EAEX,IAAAP,QAAE,EAAE,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": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAmJE;AAhJF,oBAAiD;AACjD,0BAA0C;AAC1C,qBAAsC;AACtC,wBAQO;AACP,mBAAuB;AACvB,kBAAuC;AACvC,kBAAgC;AAChC,qB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