@wordpress/patterns 2.32.0 → 2.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/api/index.js +35 -29
- package/build/api/index.js.map +7 -1
- package/build/components/allow-overrides-modal.js +149 -112
- package/build/components/allow-overrides-modal.js.map +7 -1
- package/build/components/category-selector.js +59 -38
- package/build/components/category-selector.js.map +7 -1
- package/build/components/create-pattern-modal.js +162 -111
- package/build/components/create-pattern-modal.js.map +7 -1
- package/build/components/duplicate-pattern-modal.js +85 -66
- package/build/components/duplicate-pattern-modal.js.map +7 -1
- package/build/components/index.js +50 -33
- package/build/components/index.js.map +7 -1
- package/build/components/overrides-panel.js +44 -39
- package/build/components/overrides-panel.js.map +7 -1
- package/build/components/pattern-convert-button.js +144 -133
- package/build/components/pattern-convert-button.js.map +7 -1
- package/build/components/pattern-overrides-block-controls.js +109 -109
- package/build/components/pattern-overrides-block-controls.js.map +7 -1
- package/build/components/pattern-overrides-controls.js +86 -69
- package/build/components/pattern-overrides-controls.js.map +7 -1
- package/build/components/patterns-manage-button.js +96 -97
- package/build/components/patterns-manage-button.js.map +7 -1
- package/build/components/rename-pattern-category-modal.js +122 -111
- package/build/components/rename-pattern-category-modal.js.map +7 -1
- package/build/components/rename-pattern-modal.js +95 -73
- package/build/components/rename-pattern-modal.js.map +7 -1
- package/build/components/reset-overrides-control.js +61 -57
- package/build/components/reset-overrides-control.js.map +7 -1
- package/build/constants.js +57 -23
- package/build/constants.js.map +7 -1
- package/build/index.js +27 -24
- package/build/index.js.map +7 -1
- package/build/lock-unlock.js +31 -15
- package/build/lock-unlock.js.map +7 -1
- package/build/private-apis.js +71 -48
- package/build/private-apis.js.map +7 -1
- package/build/private-hooks.js +57 -69
- package/build/private-hooks.js.map +7 -1
- package/build/store/actions.js +72 -85
- package/build/store/actions.js.map +7 -1
- package/build/store/constants.js +27 -10
- package/build/store/constants.js.map +7 -1
- package/build/store/index.js +50 -44
- 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/api/index.js +14 -25
- package/build-module/api/index.js.map +7 -1
- package/build-module/components/allow-overrides-modal.js +131 -103
- package/build-module/components/allow-overrides-modal.js.map +7 -1
- package/build-module/components/category-selector.js +35 -29
- package/build-module/components/category-selector.js.map +7 -1
- package/build-module/components/create-pattern-modal.js +137 -99
- package/build-module/components/create-pattern-modal.js.map +7 -1
- package/build-module/components/duplicate-pattern-modal.js +53 -58
- package/build-module/components/duplicate-pattern-modal.js.map +7 -1
- package/build-module/components/index.js +22 -26
- package/build-module/components/index.js.map +7 -1
- package/build-module/components/overrides-panel.js +30 -34
- package/build-module/components/overrides-panel.js.map +7 -1
- package/build-module/components/pattern-convert-button.js +120 -125
- package/build-module/components/pattern-convert-button.js.map +7 -1
- package/build-module/components/pattern-overrides-block-controls.js +100 -103
- package/build-module/components/pattern-overrides-block-controls.js.map +7 -1
- package/build-module/components/pattern-overrides-controls.js +69 -58
- package/build-module/components/pattern-overrides-controls.js.map +7 -1
- package/build-module/components/patterns-manage-button.js +78 -91
- package/build-module/components/patterns-manage-button.js.map +7 -1
- package/build-module/components/rename-pattern-category-modal.js +106 -101
- package/build-module/components/rename-pattern-category-modal.js.map +7 -1
- package/build-module/components/rename-pattern-modal.js +80 -64
- package/build-module/components/rename-pattern-modal.js.map +7 -1
- package/build-module/components/reset-overrides-control.js +46 -51
- package/build-module/components/reset-overrides-control.js.map +7 -1
- package/build-module/constants.js +29 -18
- package/build-module/constants.js.map +7 -1
- package/build-module/index.js +6 -6
- 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/private-apis.js +31 -18
- package/build-module/private-apis.js.map +7 -1
- package/build-module/private-hooks.js +35 -64
- package/build-module/private-hooks.js.map +7 -1
- package/build-module/store/actions.js +44 -74
- package/build-module/store/actions.js.map +7 -1
- package/build-module/store/constants.js +5 -5
- package/build-module/store/constants.js.map +7 -1
- package/build-module/store/index.js +13 -32
- 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 +24 -17
- package/src/components/style.scss +5 -0
- package/src/style.scss +2 -1
- package/build/index.native.js +0 -18
- package/build/index.native.js.map +0 -1
- package/build-module/index.native.js +0 -11
- package/build-module/index.native.js.map +0 -1
|
@@ -1,30 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import PatternsManageButton from './patterns-manage-button';
|
|
11
|
-
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
|
-
export default function PatternsMenuItems({
|
|
13
|
-
rootClientId
|
|
14
|
-
}) {
|
|
15
|
-
return /*#__PURE__*/_jsx(BlockSettingsMenuControls, {
|
|
16
|
-
children: ({
|
|
17
|
-
selectedClientIds,
|
|
18
|
-
onClose
|
|
19
|
-
}) => /*#__PURE__*/_jsxs(_Fragment, {
|
|
20
|
-
children: [/*#__PURE__*/_jsx(PatternConvertButton, {
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { BlockSettingsMenuControls } from "@wordpress/block-editor";
|
|
3
|
+
import PatternConvertButton from "./pattern-convert-button";
|
|
4
|
+
import PatternsManageButton from "./patterns-manage-button";
|
|
5
|
+
function PatternsMenuItems({ rootClientId }) {
|
|
6
|
+
return /* @__PURE__ */ jsx(BlockSettingsMenuControls, { children: ({ selectedClientIds, onClose }) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
7
|
+
/* @__PURE__ */ jsx(
|
|
8
|
+
PatternConvertButton,
|
|
9
|
+
{
|
|
21
10
|
clientIds: selectedClientIds,
|
|
22
|
-
rootClientId
|
|
11
|
+
rootClientId,
|
|
23
12
|
closeBlockSettingsMenu: onClose
|
|
24
|
-
}
|
|
13
|
+
}
|
|
14
|
+
),
|
|
15
|
+
selectedClientIds.length === 1 && /* @__PURE__ */ jsx(
|
|
16
|
+
PatternsManageButton,
|
|
17
|
+
{
|
|
25
18
|
clientId: selectedClientIds[0]
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
});
|
|
19
|
+
}
|
|
20
|
+
)
|
|
21
|
+
] }) });
|
|
29
22
|
}
|
|
30
|
-
|
|
23
|
+
export {
|
|
24
|
+
PatternsMenuItems as default
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/components/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { BlockSettingsMenuControls } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport PatternConvertButton from './pattern-convert-button';\nimport PatternsManageButton from './patterns-manage-button';\n\nexport default function PatternsMenuItems( { rootClientId } ) {\n\treturn (\n\t\t<BlockSettingsMenuControls>\n\t\t\t{ ( { selectedClientIds, onClose } ) => (\n\t\t\t\t<>\n\t\t\t\t\t<PatternConvertButton\n\t\t\t\t\t\tclientIds={ selectedClientIds }\n\t\t\t\t\t\trootClientId={ rootClientId }\n\t\t\t\t\t\tcloseBlockSettingsMenu={ onClose }\n\t\t\t\t\t/>\n\t\t\t\t\t{ selectedClientIds.length === 1 && (\n\t\t\t\t\t\t<PatternsManageButton\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,0BAA0B;AACjC,OAAO,0BAA0B;AAElB,SAAR,kBAAoC,EAAE,aAAa,GAAI;AAC7D,SACC,oBAAC,6BACE,WAAE,EAAE,mBAAmB,QAAQ,MAChC,iCACC;AAAA;AAAA,MAAC;AAAA;AAAA,QACA,WAAY;AAAA,QACZ;AAAA,QACA,wBAAyB;AAAA;AAAA,IAC1B;AAAA,IACE,kBAAkB,WAAW,KAC9B;AAAA,MAAC;AAAA;AAAA,QACA,UAAW,kBAAmB,CAAE;AAAA;AAAA,IACjC;AAAA,KAEF,GAEF;AAEF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,38 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
} =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return isOverridableBlock(block);
|
|
27
|
-
}), [allClientIds, getBlock]);
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import {
|
|
3
|
+
privateApis as blockEditorPrivateApis,
|
|
4
|
+
store as blockEditorStore
|
|
5
|
+
} from "@wordpress/block-editor";
|
|
6
|
+
import { PanelBody } from "@wordpress/components";
|
|
7
|
+
import { useSelect } from "@wordpress/data";
|
|
8
|
+
import { useMemo } from "@wordpress/element";
|
|
9
|
+
import { __ } from "@wordpress/i18n";
|
|
10
|
+
import { isOverridableBlock } from "../api";
|
|
11
|
+
import { unlock } from "../lock-unlock";
|
|
12
|
+
const { BlockQuickNavigation } = unlock(blockEditorPrivateApis);
|
|
13
|
+
function OverridesPanel() {
|
|
14
|
+
const allClientIds = useSelect(
|
|
15
|
+
(select) => select(blockEditorStore).getClientIdsWithDescendants(),
|
|
16
|
+
[]
|
|
17
|
+
);
|
|
18
|
+
const { getBlock } = useSelect(blockEditorStore);
|
|
19
|
+
const clientIdsWithOverrides = useMemo(
|
|
20
|
+
() => allClientIds.filter((clientId) => {
|
|
21
|
+
const block = getBlock(clientId);
|
|
22
|
+
return isOverridableBlock(block);
|
|
23
|
+
}),
|
|
24
|
+
[allClientIds, getBlock]
|
|
25
|
+
);
|
|
28
26
|
if (!clientIdsWithOverrides?.length) {
|
|
29
27
|
return null;
|
|
30
28
|
}
|
|
31
|
-
return
|
|
32
|
-
title: __('Overrides'),
|
|
33
|
-
children: /*#__PURE__*/_jsx(BlockQuickNavigation, {
|
|
34
|
-
clientIds: clientIdsWithOverrides
|
|
35
|
-
})
|
|
36
|
-
});
|
|
29
|
+
return /* @__PURE__ */ jsx(PanelBody, { title: __("Overrides"), children: /* @__PURE__ */ jsx(BlockQuickNavigation, { clientIds: clientIdsWithOverrides }) });
|
|
37
30
|
}
|
|
38
|
-
|
|
31
|
+
export {
|
|
32
|
+
OverridesPanel as default
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=overrides-panel.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/components/overrides-panel.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tprivateApis as blockEditorPrivateApis,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { PanelBody } from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\nimport { useMemo } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { isOverridableBlock } from '../api';\nimport { unlock } from '../lock-unlock';\n\nconst { BlockQuickNavigation } = unlock( blockEditorPrivateApis );\n\nexport default function OverridesPanel() {\n\tconst allClientIds = useSelect(\n\t\t( select ) => select( blockEditorStore ).getClientIdsWithDescendants(),\n\t\t[]\n\t);\n\tconst { getBlock } = useSelect( blockEditorStore );\n\tconst clientIdsWithOverrides = useMemo(\n\t\t() =>\n\t\t\tallClientIds.filter( ( clientId ) => {\n\t\t\t\tconst block = getBlock( clientId );\n\t\t\t\treturn isOverridableBlock( block );\n\t\t\t} ),\n\t\t[ allClientIds, getBlock ]\n\t);\n\n\tif ( ! clientIdsWithOverrides?.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<PanelBody title={ __( 'Overrides' ) }>\n\t\t\t<BlockQuickNavigation clientIds={ clientIdsWithOverrides } />\n\t\t</PanelBody>\n\t);\n}\n"],
|
|
5
|
+
"mappings": "AAyCG;AAtCH;AAAA,EACC,eAAe;AAAA,EACf,SAAS;AAAA,OACH;AACP,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAC1B,SAAS,eAAe;AACxB,SAAS,UAAU;AAKnB,SAAS,0BAA0B;AACnC,SAAS,cAAc;AAEvB,MAAM,EAAE,qBAAqB,IAAI,OAAQ,sBAAuB;AAEjD,SAAR,iBAAkC;AACxC,QAAM,eAAe;AAAA,IACpB,CAAE,WAAY,OAAQ,gBAAiB,EAAE,4BAA4B;AAAA,IACrE,CAAC;AAAA,EACF;AACA,QAAM,EAAE,SAAS,IAAI,UAAW,gBAAiB;AACjD,QAAM,yBAAyB;AAAA,IAC9B,MACC,aAAa,OAAQ,CAAE,aAAc;AACpC,YAAM,QAAQ,SAAU,QAAS;AACjC,aAAO,mBAAoB,KAAM;AAAA,IAClC,CAAE;AAAA,IACH,CAAE,cAAc,QAAS;AAAA,EAC1B;AAEA,MAAK,CAAE,wBAAwB,QAAS;AACvC,WAAO;AAAA,EACR;AAEA,SACC,oBAAC,aAAU,OAAQ,GAAI,WAAY,GAClC,8BAAC,wBAAqB,WAAY,wBAAyB,GAC5D;AAEF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,154 +1,149 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
import { store as
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
import {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
* Menu control to convert block(s) to a pattern block.
|
|
23
|
-
*
|
|
24
|
-
* @param {Object} props Component props.
|
|
25
|
-
* @param {string[]} props.clientIds Client ids of selected blocks.
|
|
26
|
-
* @param {string} props.rootClientId ID of the currently selected top-level block.
|
|
27
|
-
* @param {()=>void} props.closeBlockSettingsMenu Callback to close the block settings menu dropdown.
|
|
28
|
-
* @return {import('react').ComponentType} The menu control or null.
|
|
29
|
-
*/
|
|
30
|
-
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
31
|
-
export default function PatternConvertButton({
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import {
|
|
3
|
+
hasBlockSupport,
|
|
4
|
+
isReusableBlock,
|
|
5
|
+
createBlock,
|
|
6
|
+
serialize,
|
|
7
|
+
getBlockType
|
|
8
|
+
} from "@wordpress/blocks";
|
|
9
|
+
import { store as blockEditorStore } from "@wordpress/block-editor";
|
|
10
|
+
import { useState, useCallback } from "@wordpress/element";
|
|
11
|
+
import { MenuItem } from "@wordpress/components";
|
|
12
|
+
import { symbol } from "@wordpress/icons";
|
|
13
|
+
import { useSelect, useDispatch } from "@wordpress/data";
|
|
14
|
+
import { store as coreStore } from "@wordpress/core-data";
|
|
15
|
+
import { __, sprintf } from "@wordpress/i18n";
|
|
16
|
+
import { store as noticesStore } from "@wordpress/notices";
|
|
17
|
+
import { store as patternsStore } from "../store";
|
|
18
|
+
import CreatePatternModal from "./create-pattern-modal";
|
|
19
|
+
import { unlock } from "../lock-unlock";
|
|
20
|
+
import { PATTERN_SYNC_TYPES } from "../constants";
|
|
21
|
+
function PatternConvertButton({
|
|
32
22
|
clientIds,
|
|
33
23
|
rootClientId,
|
|
34
24
|
closeBlockSettingsMenu
|
|
35
25
|
}) {
|
|
36
|
-
const {
|
|
37
|
-
|
|
38
|
-
} = useDispatch(
|
|
39
|
-
const {
|
|
40
|
-
replaceBlocks,
|
|
41
|
-
updateBlockAttributes
|
|
42
|
-
} = useDispatch(blockEditorStore);
|
|
43
|
-
// Ignore reason: false positive of the lint rule.
|
|
44
|
-
// eslint-disable-next-line @wordpress/no-unused-vars-before-return
|
|
45
|
-
const {
|
|
46
|
-
setEditingPattern
|
|
47
|
-
} = unlock(useDispatch(patternsStore));
|
|
26
|
+
const { createSuccessNotice } = useDispatch(noticesStore);
|
|
27
|
+
const { replaceBlocks, updateBlockAttributes } = useDispatch(blockEditorStore);
|
|
28
|
+
const { setEditingPattern } = unlock(useDispatch(patternsStore));
|
|
48
29
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
49
|
-
const {
|
|
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
|
-
|
|
94
|
-
|
|
95
|
-
getBlocksByClientId
|
|
96
|
-
|
|
97
|
-
const getContent = useCallback(() => serialize(getBlocksByClientId(clientIds)), [getBlocksByClientId, clientIds]);
|
|
30
|
+
const { getBlockAttributes } = useSelect(blockEditorStore);
|
|
31
|
+
const canConvert = useSelect(
|
|
32
|
+
(select) => {
|
|
33
|
+
const { canUser } = select(coreStore);
|
|
34
|
+
const {
|
|
35
|
+
getBlocksByClientId: getBlocksByClientId2,
|
|
36
|
+
canInsertBlockType,
|
|
37
|
+
getBlockRootClientId
|
|
38
|
+
} = select(blockEditorStore);
|
|
39
|
+
const rootId = rootClientId || (clientIds.length > 0 ? getBlockRootClientId(clientIds[0]) : void 0);
|
|
40
|
+
const blocks = getBlocksByClientId2(clientIds) ?? [];
|
|
41
|
+
const hasReusableBlockSupport = (blockName) => {
|
|
42
|
+
const blockType = getBlockType(blockName);
|
|
43
|
+
const hasParent = blockType && "parent" in blockType;
|
|
44
|
+
return hasBlockSupport(blockName, "reusable", !hasParent);
|
|
45
|
+
};
|
|
46
|
+
const isSyncedPattern = blocks.length === 1 && blocks[0] && isReusableBlock(blocks[0]) && !!select(coreStore).getEntityRecord(
|
|
47
|
+
"postType",
|
|
48
|
+
"wp_block",
|
|
49
|
+
blocks[0].attributes.ref
|
|
50
|
+
);
|
|
51
|
+
const isUnsyncedPattern = window?.__experimentalContentOnlyPatternInsertion && blocks.length === 1 && blocks?.[0]?.attributes?.metadata?.patternName;
|
|
52
|
+
const _canConvert = (
|
|
53
|
+
// Hide when this is already a pattern.
|
|
54
|
+
!isUnsyncedPattern && !isSyncedPattern && // Hide when patterns are disabled.
|
|
55
|
+
canInsertBlockType("core/block", rootId) && blocks.every(
|
|
56
|
+
(block) => (
|
|
57
|
+
// Guard against the case where a regular block has *just* been converted.
|
|
58
|
+
!!block && // Hide on invalid blocks.
|
|
59
|
+
block.isValid && // Hide when block doesn't support being made into a pattern.
|
|
60
|
+
hasReusableBlockSupport(block.name)
|
|
61
|
+
)
|
|
62
|
+
) && // Hide when current doesn't have permission to do that.
|
|
63
|
+
// Blocks refers to the wp_block post type, this checks the ability to create a post of that type.
|
|
64
|
+
!!canUser("create", {
|
|
65
|
+
kind: "postType",
|
|
66
|
+
name: "wp_block"
|
|
67
|
+
})
|
|
68
|
+
);
|
|
69
|
+
return _canConvert;
|
|
70
|
+
},
|
|
71
|
+
[clientIds, rootClientId]
|
|
72
|
+
);
|
|
73
|
+
const { getBlocksByClientId } = useSelect(blockEditorStore);
|
|
74
|
+
const getContent = useCallback(
|
|
75
|
+
() => serialize(getBlocksByClientId(clientIds)),
|
|
76
|
+
[getBlocksByClientId, clientIds]
|
|
77
|
+
);
|
|
98
78
|
if (!canConvert) {
|
|
99
79
|
return null;
|
|
100
80
|
}
|
|
101
|
-
const handleSuccess = ({
|
|
102
|
-
pattern
|
|
103
|
-
}) => {
|
|
81
|
+
const handleSuccess = ({ pattern }) => {
|
|
104
82
|
if (pattern.wp_pattern_sync_status === PATTERN_SYNC_TYPES.unsynced) {
|
|
105
83
|
if (clientIds?.length === 1) {
|
|
106
84
|
const existingAttributes = getBlockAttributes(clientIds[0]);
|
|
107
85
|
updateBlockAttributes(clientIds[0], {
|
|
108
86
|
metadata: {
|
|
109
|
-
...
|
|
87
|
+
...existingAttributes?.metadata ? existingAttributes.metadata : {},
|
|
110
88
|
patternName: `core/block/${pattern.id}`,
|
|
111
89
|
name: pattern.title.raw
|
|
112
90
|
}
|
|
113
91
|
});
|
|
114
92
|
}
|
|
115
93
|
} else {
|
|
116
|
-
const newBlock = createBlock(
|
|
94
|
+
const newBlock = createBlock("core/block", {
|
|
117
95
|
ref: pattern.id
|
|
118
96
|
});
|
|
119
97
|
replaceBlocks(clientIds, newBlock);
|
|
120
98
|
setEditingPattern(newBlock.clientId, true);
|
|
121
99
|
closeBlockSettingsMenu();
|
|
122
100
|
}
|
|
123
|
-
createSuccessNotice(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
101
|
+
createSuccessNotice(
|
|
102
|
+
pattern.wp_pattern_sync_status === PATTERN_SYNC_TYPES.unsynced ? sprintf(
|
|
103
|
+
// translators: %s: the name the user has given to the pattern.
|
|
104
|
+
__("Unsynced pattern created: %s"),
|
|
105
|
+
pattern.title.raw
|
|
106
|
+
) : sprintf(
|
|
107
|
+
// translators: %s: the name the user has given to the pattern.
|
|
108
|
+
__("Synced pattern created: %s"),
|
|
109
|
+
pattern.title.raw
|
|
110
|
+
),
|
|
111
|
+
{
|
|
112
|
+
type: "snackbar",
|
|
113
|
+
id: "convert-to-pattern-success"
|
|
114
|
+
}
|
|
115
|
+
);
|
|
131
116
|
setIsModalOpen(false);
|
|
132
117
|
};
|
|
133
|
-
return
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
118
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
119
|
+
/* @__PURE__ */ jsx(
|
|
120
|
+
MenuItem,
|
|
121
|
+
{
|
|
122
|
+
icon: symbol,
|
|
123
|
+
onClick: () => setIsModalOpen(true),
|
|
124
|
+
"aria-expanded": isModalOpen,
|
|
125
|
+
"aria-haspopup": "dialog",
|
|
126
|
+
children: __("Create pattern")
|
|
127
|
+
}
|
|
128
|
+
),
|
|
129
|
+
isModalOpen && /* @__PURE__ */ jsx(
|
|
130
|
+
CreatePatternModal,
|
|
131
|
+
{
|
|
132
|
+
content: getContent,
|
|
133
|
+
onSuccess: (pattern) => {
|
|
134
|
+
handleSuccess(pattern);
|
|
135
|
+
},
|
|
136
|
+
onError: () => {
|
|
137
|
+
setIsModalOpen(false);
|
|
138
|
+
},
|
|
139
|
+
onClose: () => {
|
|
140
|
+
setIsModalOpen(false);
|
|
141
|
+
}
|
|
150
142
|
}
|
|
151
|
-
|
|
152
|
-
});
|
|
143
|
+
)
|
|
144
|
+
] });
|
|
153
145
|
}
|
|
154
|
-
|
|
146
|
+
export {
|
|
147
|
+
PatternConvertButton as default
|
|
148
|
+
};
|
|
149
|
+
//# sourceMappingURL=pattern-convert-button.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{"version":3,"names":["hasBlockSupport","isReusableBlock","createBlock","serialize","getBlockType","store","blockEditorStore","useState","useCallback","MenuItem","symbol","useSelect","useDispatch","coreStore","__","sprintf","noticesStore","patternsStore","CreatePatternModal","unlock","PATTERN_SYNC_TYPES","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","PatternConvertButton","clientIds","rootClientId","closeBlockSettingsMenu","createSuccessNotice","replaceBlocks","updateBlockAttributes","setEditingPattern","isModalOpen","setIsModalOpen","getBlockAttributes","canConvert","select","_getBlocksByClientId","canUser","getBlocksByClientId","canInsertBlockType","getBlockRootClientId","rootId","length","undefined","blocks","hasReusableBlockSupport","blockName","blockType","hasParent","isSyncedPattern","getEntityRecord","attributes","ref","isUnsyncedPattern","window","__experimentalContentOnlyPatternInsertion","metadata","patternName","_canConvert","every","block","isValid","name","kind","getContent","handleSuccess","pattern","wp_pattern_sync_status","unsynced","existingAttributes","id","title","raw","newBlock","clientId","type","children","icon","onClick","content","onSuccess","onError","onClose"],"sources":["@wordpress/patterns/src/components/pattern-convert-button.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\thasBlockSupport,\n\tisReusableBlock,\n\tcreateBlock,\n\tserialize,\n\tgetBlockType,\n} from '@wordpress/blocks';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { useState, useCallback } from '@wordpress/element';\nimport { MenuItem } from '@wordpress/components';\nimport { symbol } from '@wordpress/icons';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n/**\n * Internal dependencies\n */\nimport { store as patternsStore } from '../store';\nimport CreatePatternModal from './create-pattern-modal';\nimport { unlock } from '../lock-unlock';\nimport { PATTERN_SYNC_TYPES } from '../constants';\n\n/**\n * Menu control to convert block(s) to a pattern 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.closeBlockSettingsMenu Callback to close the block settings menu dropdown.\n * @return {import('react').ComponentType} The menu control or null.\n */\nexport default function PatternConvertButton( {\n\tclientIds,\n\trootClientId,\n\tcloseBlockSettingsMenu,\n} ) {\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\tconst { replaceBlocks, updateBlockAttributes } =\n\t\tuseDispatch( blockEditorStore );\n\t// Ignore reason: false positive of the lint rule.\n\t// eslint-disable-next-line @wordpress/no-unused-vars-before-return\n\tconst { setEditingPattern } = unlock( useDispatch( patternsStore ) );\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\tconst { getBlockAttributes } = useSelect( blockEditorStore );\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\t// Check if the block has reusable support defined.\n\t\t\tconst hasReusableBlockSupport = ( blockName ) => {\n\t\t\t\tconst blockType = getBlockType( blockName );\n\t\t\t\tconst hasParent = blockType && 'parent' in blockType;\n\n\t\t\t\t// If the block has a parent, check with false as default, otherwise with true.\n\t\t\t\treturn hasBlockSupport( blockName, 'reusable', ! hasParent );\n\t\t\t};\n\n\t\t\tconst isSyncedPattern =\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 isUnsyncedPattern =\n\t\t\t\twindow?.__experimentalContentOnlyPatternInsertion &&\n\t\t\t\tblocks.length === 1 &&\n\t\t\t\tblocks?.[ 0 ]?.attributes?.metadata?.patternName;\n\n\t\t\tconst _canConvert =\n\t\t\t\t// Hide when this is already a pattern.\n\t\t\t\t! isUnsyncedPattern &&\n\t\t\t\t! isSyncedPattern &&\n\t\t\t\t// Hide when patterns 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 into a pattern.\n\t\t\t\t\t\thasReusableBlockSupport( block.name )\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\tconst { getBlocksByClientId } = useSelect( blockEditorStore );\n\tconst getContent = useCallback(\n\t\t() => serialize( getBlocksByClientId( clientIds ) ),\n\t\t[ getBlocksByClientId, clientIds ]\n\t);\n\n\tif ( ! canConvert ) {\n\t\treturn null;\n\t}\n\n\tconst handleSuccess = ( { pattern } ) => {\n\t\tif ( pattern.wp_pattern_sync_status === PATTERN_SYNC_TYPES.unsynced ) {\n\t\t\tif ( clientIds?.length === 1 ) {\n\t\t\t\tconst existingAttributes = getBlockAttributes( clientIds[ 0 ] );\n\t\t\t\tupdateBlockAttributes( clientIds[ 0 ], {\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t...( existingAttributes?.metadata\n\t\t\t\t\t\t\t? existingAttributes.metadata\n\t\t\t\t\t\t\t: {} ),\n\t\t\t\t\t\tpatternName: `core/block/${ pattern.id }`,\n\t\t\t\t\t\tname: pattern.title.raw,\n\t\t\t\t\t},\n\t\t\t\t} );\n\t\t\t}\n\t\t} else {\n\t\t\tconst newBlock = createBlock( 'core/block', {\n\t\t\t\tref: pattern.id,\n\t\t\t} );\n\n\t\t\treplaceBlocks( clientIds, newBlock );\n\t\t\tsetEditingPattern( newBlock.clientId, true );\n\t\t\tcloseBlockSettingsMenu();\n\t\t}\n\n\t\tcreateSuccessNotice(\n\t\t\tpattern.wp_pattern_sync_status === PATTERN_SYNC_TYPES.unsynced\n\t\t\t\t? sprintf(\n\t\t\t\t\t\t// translators: %s: the name the user has given to the pattern.\n\t\t\t\t\t\t__( 'Unsynced pattern created: %s' ),\n\t\t\t\t\t\tpattern.title.raw\n\t\t\t\t )\n\t\t\t\t: sprintf(\n\t\t\t\t\t\t// translators: %s: the name the user has given to the pattern.\n\t\t\t\t\t\t__( 'Synced pattern created: %s' ),\n\t\t\t\t\t\tpattern.title.raw\n\t\t\t\t ),\n\t\t\t{\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'convert-to-pattern-success',\n\t\t\t}\n\t\t);\n\t\tsetIsModalOpen( false );\n\t};\n\treturn (\n\t\t<>\n\t\t\t<MenuItem\n\t\t\t\ticon={ symbol }\n\t\t\t\tonClick={ () => setIsModalOpen( true ) }\n\t\t\t\taria-expanded={ isModalOpen }\n\t\t\t\taria-haspopup=\"dialog\"\n\t\t\t>\n\t\t\t\t{ __( 'Create pattern' ) }\n\t\t\t</MenuItem>\n\t\t\t{ isModalOpen && (\n\t\t\t\t<CreatePatternModal\n\t\t\t\t\tcontent={ getContent }\n\t\t\t\t\tonSuccess={ ( pattern ) => {\n\t\t\t\t\t\thandleSuccess( pattern );\n\t\t\t\t\t} }\n\t\t\t\t\tonError={ () => {\n\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t} }\n\t\t\t\t\tonClose={ () => {\n\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SACCA,eAAe,EACfC,eAAe,EACfC,WAAW,EACXC,SAAS,EACTC,YAAY,QACN,mBAAmB;AAC1B,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,yBAAyB;AACnE,SAASC,QAAQ,EAAEC,WAAW,QAAQ,oBAAoB;AAC1D,SAASC,QAAQ,QAAQ,uBAAuB;AAChD,SAASC,MAAM,QAAQ,kBAAkB;AACzC,SAASC,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACxD,SAASP,KAAK,IAAIQ,SAAS,QAAQ,sBAAsB;AACzD,SAASC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AAC7C,SAASV,KAAK,IAAIW,YAAY,QAAQ,oBAAoB;AAC1D;AACA;AACA;AACA,SAASX,KAAK,IAAIY,aAAa,QAAQ,UAAU;AACjD,OAAOC,kBAAkB,MAAM,wBAAwB;AACvD,SAASC,MAAM,QAAQ,gBAAgB;AACvC,SAASC,kBAAkB,QAAQ,cAAc;;AAEjD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AARA,SAAAC,GAAA,IAAAC,IAAA,EAAAC,QAAA,IAAAC,SAAA,EAAAC,IAAA,IAAAC,KAAA;AASA,eAAe,SAASC,oBAAoBA,CAAE;E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,cAAc,CAAE,IAAK,CAAG;MACxC,iBAAgBD,WAAa;MAC7B,iBAAc,QAAQ;MAAA6C,QAAA,EAEpBlE,EAAE,CAAE,gBAAiB;IAAC,CACf,CAAC,EACTqB,WAAW,iBACZb,IAAA,CAACJ,kBAAkB;MAClBiE,OAAO,EAAGf,UAAY;MACtBgB,SAAS,EAAKd,OAAO,IAAM;QAC1BD,aAAa,CAAEC,OAAQ,CAAC;MACzB,CAAG;MACHe,OAAO,EAAGA,CAAA,KAAM;QACfjD,cAAc,CAAE,KAAM,CAAC;MACxB,CAAG;MACHkD,OAAO,EAAGA,CAAA,KAAM;QACflD,cAAc,CAAE,KAAM,CAAC;MACxB;IAAG,CACH,CACD;EAAA,CACA,CAAC;AAEL","ignoreList":[]}
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/components/pattern-convert-button.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\thasBlockSupport,\n\tisReusableBlock,\n\tcreateBlock,\n\tserialize,\n\tgetBlockType,\n} from '@wordpress/blocks';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { useState, useCallback } from '@wordpress/element';\nimport { MenuItem } from '@wordpress/components';\nimport { symbol } from '@wordpress/icons';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n/**\n * Internal dependencies\n */\nimport { store as patternsStore } from '../store';\nimport CreatePatternModal from './create-pattern-modal';\nimport { unlock } from '../lock-unlock';\nimport { PATTERN_SYNC_TYPES } from '../constants';\n\n/**\n * Menu control to convert block(s) to a pattern 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.closeBlockSettingsMenu Callback to close the block settings menu dropdown.\n * @return {import('react').ComponentType} The menu control or null.\n */\nexport default function PatternConvertButton( {\n\tclientIds,\n\trootClientId,\n\tcloseBlockSettingsMenu,\n} ) {\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\tconst { replaceBlocks, updateBlockAttributes } =\n\t\tuseDispatch( blockEditorStore );\n\t// Ignore reason: false positive of the lint rule.\n\t// eslint-disable-next-line @wordpress/no-unused-vars-before-return\n\tconst { setEditingPattern } = unlock( useDispatch( patternsStore ) );\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\tconst { getBlockAttributes } = useSelect( blockEditorStore );\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\t// Check if the block has reusable support defined.\n\t\t\tconst hasReusableBlockSupport = ( blockName ) => {\n\t\t\t\tconst blockType = getBlockType( blockName );\n\t\t\t\tconst hasParent = blockType && 'parent' in blockType;\n\n\t\t\t\t// If the block has a parent, check with false as default, otherwise with true.\n\t\t\t\treturn hasBlockSupport( blockName, 'reusable', ! hasParent );\n\t\t\t};\n\n\t\t\tconst isSyncedPattern =\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 isUnsyncedPattern =\n\t\t\t\twindow?.__experimentalContentOnlyPatternInsertion &&\n\t\t\t\tblocks.length === 1 &&\n\t\t\t\tblocks?.[ 0 ]?.attributes?.metadata?.patternName;\n\n\t\t\tconst _canConvert =\n\t\t\t\t// Hide when this is already a pattern.\n\t\t\t\t! isUnsyncedPattern &&\n\t\t\t\t! isSyncedPattern &&\n\t\t\t\t// Hide when patterns 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 into a pattern.\n\t\t\t\t\t\thasReusableBlockSupport( block.name )\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\tconst { getBlocksByClientId } = useSelect( blockEditorStore );\n\tconst getContent = useCallback(\n\t\t() => serialize( getBlocksByClientId( clientIds ) ),\n\t\t[ getBlocksByClientId, clientIds ]\n\t);\n\n\tif ( ! canConvert ) {\n\t\treturn null;\n\t}\n\n\tconst handleSuccess = ( { pattern } ) => {\n\t\tif ( pattern.wp_pattern_sync_status === PATTERN_SYNC_TYPES.unsynced ) {\n\t\t\tif ( clientIds?.length === 1 ) {\n\t\t\t\tconst existingAttributes = getBlockAttributes( clientIds[ 0 ] );\n\t\t\t\tupdateBlockAttributes( clientIds[ 0 ], {\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t...( existingAttributes?.metadata\n\t\t\t\t\t\t\t? existingAttributes.metadata\n\t\t\t\t\t\t\t: {} ),\n\t\t\t\t\t\tpatternName: `core/block/${ pattern.id }`,\n\t\t\t\t\t\tname: pattern.title.raw,\n\t\t\t\t\t},\n\t\t\t\t} );\n\t\t\t}\n\t\t} else {\n\t\t\tconst newBlock = createBlock( 'core/block', {\n\t\t\t\tref: pattern.id,\n\t\t\t} );\n\n\t\t\treplaceBlocks( clientIds, newBlock );\n\t\t\tsetEditingPattern( newBlock.clientId, true );\n\t\t\tcloseBlockSettingsMenu();\n\t\t}\n\n\t\tcreateSuccessNotice(\n\t\t\tpattern.wp_pattern_sync_status === PATTERN_SYNC_TYPES.unsynced\n\t\t\t\t? sprintf(\n\t\t\t\t\t\t// translators: %s: the name the user has given to the pattern.\n\t\t\t\t\t\t__( 'Unsynced pattern created: %s' ),\n\t\t\t\t\t\tpattern.title.raw\n\t\t\t\t )\n\t\t\t\t: sprintf(\n\t\t\t\t\t\t// translators: %s: the name the user has given to the pattern.\n\t\t\t\t\t\t__( 'Synced pattern created: %s' ),\n\t\t\t\t\t\tpattern.title.raw\n\t\t\t\t ),\n\t\t\t{\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'convert-to-pattern-success',\n\t\t\t}\n\t\t);\n\t\tsetIsModalOpen( false );\n\t};\n\treturn (\n\t\t<>\n\t\t\t<MenuItem\n\t\t\t\ticon={ symbol }\n\t\t\t\tonClick={ () => setIsModalOpen( true ) }\n\t\t\t\taria-expanded={ isModalOpen }\n\t\t\t\taria-haspopup=\"dialog\"\n\t\t\t>\n\t\t\t\t{ __( 'Create pattern' ) }\n\t\t\t</MenuItem>\n\t\t\t{ isModalOpen && (\n\t\t\t\t<CreatePatternModal\n\t\t\t\t\tcontent={ getContent }\n\t\t\t\t\tonSuccess={ ( pattern ) => {\n\t\t\t\t\t\thandleSuccess( pattern );\n\t\t\t\t\t} }\n\t\t\t\t\tonError={ () => {\n\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t} }\n\t\t\t\t\tonClose={ () => {\n\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t} }\n\t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