@wordpress/patterns 2.41.1-next.v.202603102151.0 → 2.42.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/CHANGELOG.md +2 -0
- package/build/components/patterns-manage-button.cjs +35 -21
- package/build/components/patterns-manage-button.cjs.map +3 -3
- package/build-module/components/patterns-manage-button.mjs +39 -22
- package/build-module/components/patterns-manage-button.mjs.map +2 -2
- package/package.json +17 -17
- package/src/components/patterns-manage-button.js +53 -21
package/CHANGELOG.md
CHANGED
|
@@ -26,6 +26,7 @@ var import_components = require("@wordpress/components");
|
|
|
26
26
|
var import_i18n = require("@wordpress/i18n");
|
|
27
27
|
var import_blocks = require("@wordpress/blocks");
|
|
28
28
|
var import_data = require("@wordpress/data");
|
|
29
|
+
var import_element = require("@wordpress/element");
|
|
29
30
|
var import_block_editor = require("@wordpress/block-editor");
|
|
30
31
|
var import_url = require("@wordpress/url");
|
|
31
32
|
var import_core_data = require("@wordpress/core-data");
|
|
@@ -33,6 +34,7 @@ var import_store = require("../store/index.cjs");
|
|
|
33
34
|
var import_lock_unlock = require("../lock-unlock.cjs");
|
|
34
35
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
35
36
|
function PatternsManageButton({ clientId, onClose }) {
|
|
37
|
+
const [showConfirmDialog, setShowConfirmDialog] = (0, import_element.useState)(false);
|
|
36
38
|
const {
|
|
37
39
|
attributes,
|
|
38
40
|
canDetach,
|
|
@@ -84,28 +86,40 @@ function PatternsManageButton({ clientId, onClose }) {
|
|
|
84
86
|
if (!isVisible || !canEdit) {
|
|
85
87
|
return null;
|
|
86
88
|
}
|
|
89
|
+
const handleDetach = () => {
|
|
90
|
+
if (isSyncedPattern) {
|
|
91
|
+
convertSyncedPatternToStatic(clientId);
|
|
92
|
+
}
|
|
93
|
+
if (isUnsyncedPattern) {
|
|
94
|
+
const { patternName, ...attributesWithoutPatternName } = attributes?.metadata ?? {};
|
|
95
|
+
updateBlockAttributes(clientId, {
|
|
96
|
+
metadata: attributesWithoutPatternName
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
onClose?.();
|
|
100
|
+
setShowConfirmDialog(false);
|
|
101
|
+
};
|
|
87
102
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
88
|
-
canDetach && /* @__PURE__ */ (0, import_jsx_runtime.
|
|
89
|
-
import_components.MenuItem,
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
),
|
|
103
|
+
canDetach && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
104
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.MenuItem, { onClick: () => setShowConfirmDialog(true), children: isSyncedPattern ? (0, import_i18n.__)("Disconnect pattern") : (0, import_i18n.__)("Detach pattern") }),
|
|
105
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
106
|
+
import_components.__experimentalConfirmDialog,
|
|
107
|
+
{
|
|
108
|
+
isOpen: showConfirmDialog,
|
|
109
|
+
onConfirm: handleDetach,
|
|
110
|
+
onCancel: () => setShowConfirmDialog(false),
|
|
111
|
+
confirmButtonText: isSyncedPattern ? (0, import_i18n.__)("Disconnect") : (0, import_i18n.__)("Detach"),
|
|
112
|
+
size: "medium",
|
|
113
|
+
title: isSyncedPattern ? (0, import_i18n.__)("Disconnect pattern?") : (0, import_i18n.__)("Detach pattern?"),
|
|
114
|
+
__experimentalHideHeader: false,
|
|
115
|
+
children: isSyncedPattern ? (0, import_i18n.__)(
|
|
116
|
+
"The blocks will be separated from the original pattern and will be fully editable. Future changes to the pattern will not apply here."
|
|
117
|
+
) : (0, import_i18n.__)(
|
|
118
|
+
"Blocks will no longer be associated with this pattern and will be fully editable."
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
)
|
|
122
|
+
] }),
|
|
109
123
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.MenuItem, { href: managePatternsUrl, children: (0, import_i18n.__)("Manage patterns") })
|
|
110
124
|
] });
|
|
111
125
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/components/patterns-manage-button.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,
|
|
6
|
-
"names": ["blockEditorStore", "coreStore", "patternsStore"]
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tMenuItem,\n\t__experimentalConfirmDialog as ConfirmDialog,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { isReusableBlock } from '@wordpress/blocks';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useState } from '@wordpress/element';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { addQueryArgs } from '@wordpress/url';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as patternsStore } from '../store';\nimport { unlock } from '../lock-unlock';\n\nfunction PatternsManageButton( { clientId, onClose } ) {\n\tconst [ showConfirmDialog, setShowConfirmDialog ] = useState( false );\n\n\tconst {\n\t\tattributes,\n\t\tcanDetach,\n\t\tisVisible,\n\t\tmanagePatternsUrl,\n\t\tisSyncedPattern,\n\t\tisUnsyncedPattern,\n\t\tcanEdit,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst { canRemoveBlock, getBlock, canEditBlock } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst { canUser } = select( coreStore );\n\t\t\tconst block = getBlock( clientId );\n\n\t\t\tconst _isUnsyncedPattern =\n\t\t\t\t!! block?.attributes?.metadata?.patternName;\n\n\t\t\tconst _isSyncedPattern =\n\t\t\t\t!! block &&\n\t\t\t\tisReusableBlock( block ) &&\n\t\t\t\t!! canUser( 'update', {\n\t\t\t\t\tkind: 'postType',\n\t\t\t\t\tname: 'wp_block',\n\t\t\t\t\tid: block.attributes.ref,\n\t\t\t\t} );\n\n\t\t\treturn {\n\t\t\t\tattributes: block.attributes,\n\t\t\t\tcanEdit: canEditBlock( clientId ),\n\t\t\t\t// For unsynced patterns, detaching is simply removing the `patternName` attribute.\n\t\t\t\t// For synced patterns, the `core:block` block is replaced with its inner blocks,\n\t\t\t\t// so checking whether `canRemoveBlock` is possible is required.\n\t\t\t\tcanDetach:\n\t\t\t\t\t_isUnsyncedPattern ||\n\t\t\t\t\t( _isSyncedPattern && canRemoveBlock( clientId ) ),\n\t\t\t\tisUnsyncedPattern: _isUnsyncedPattern,\n\t\t\t\tisSyncedPattern: _isSyncedPattern,\n\t\t\t\tisVisible: _isUnsyncedPattern || _isSyncedPattern,\n\t\t\t\t// The site editor and templates both check whether the user\n\t\t\t\t// has edit_theme_options capabilities. We can leverage that here\n\t\t\t\t// and omit the manage patterns link if the user can't access it.\n\t\t\t\tmanagePatternsUrl: canUser( 'create', {\n\t\t\t\t\tkind: 'postType',\n\t\t\t\t\tname: 'wp_template',\n\t\t\t\t} )\n\t\t\t\t\t? addQueryArgs( 'site-editor.php', {\n\t\t\t\t\t\t\tp: '/pattern',\n\t\t\t\t\t } )\n\t\t\t\t\t: addQueryArgs( 'edit.php', {\n\t\t\t\t\t\t\tpost_type: 'wp_block',\n\t\t\t\t\t } ),\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst { updateBlockAttributes } = useDispatch( blockEditorStore );\n\n\t// Ignore reason: false positive of the lint rule.\n\t// eslint-disable-next-line @wordpress/no-unused-vars-before-return\n\tconst { convertSyncedPatternToStatic } = unlock(\n\t\tuseDispatch( patternsStore )\n\t);\n\n\tif ( ! isVisible || ! canEdit ) {\n\t\treturn null;\n\t}\n\n\tconst handleDetach = () => {\n\t\tif ( isSyncedPattern ) {\n\t\t\tconvertSyncedPatternToStatic( clientId );\n\t\t}\n\n\t\tif ( isUnsyncedPattern ) {\n\t\t\tconst { patternName, ...attributesWithoutPatternName } =\n\t\t\t\tattributes?.metadata ?? {};\n\t\t\tupdateBlockAttributes( clientId, {\n\t\t\t\tmetadata: attributesWithoutPatternName,\n\t\t\t} );\n\t\t}\n\t\tonClose?.();\n\t\tsetShowConfirmDialog( false );\n\t};\n\n\treturn (\n\t\t<>\n\t\t\t{ canDetach && (\n\t\t\t\t<>\n\t\t\t\t\t<MenuItem onClick={ () => setShowConfirmDialog( true ) }>\n\t\t\t\t\t\t{ isSyncedPattern\n\t\t\t\t\t\t\t? __( 'Disconnect pattern' )\n\t\t\t\t\t\t\t: __( 'Detach pattern' ) }\n\t\t\t\t\t</MenuItem>\n\t\t\t\t\t<ConfirmDialog\n\t\t\t\t\t\tisOpen={ showConfirmDialog }\n\t\t\t\t\t\tonConfirm={ handleDetach }\n\t\t\t\t\t\tonCancel={ () => setShowConfirmDialog( false ) }\n\t\t\t\t\t\tconfirmButtonText={\n\t\t\t\t\t\t\tisSyncedPattern\n\t\t\t\t\t\t\t\t? __( 'Disconnect' )\n\t\t\t\t\t\t\t\t: __( 'Detach' )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsize=\"medium\"\n\t\t\t\t\t\ttitle={\n\t\t\t\t\t\t\tisSyncedPattern\n\t\t\t\t\t\t\t\t? __( 'Disconnect pattern?' )\n\t\t\t\t\t\t\t\t: __( 'Detach pattern?' )\n\t\t\t\t\t\t}\n\t\t\t\t\t\t__experimentalHideHeader={ false }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ isSyncedPattern\n\t\t\t\t\t\t\t? __(\n\t\t\t\t\t\t\t\t\t'The blocks will be separated from the original pattern and will be fully editable. Future changes to the pattern will not apply here.'\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: __(\n\t\t\t\t\t\t\t\t\t'Blocks will no longer be associated with this pattern and will be fully editable.'\n\t\t\t\t\t\t\t ) }\n\t\t\t\t\t</ConfirmDialog>\n\t\t\t\t</>\n\t\t\t) }\n\t\t\t<MenuItem href={ managePatternsUrl }>\n\t\t\t\t{ __( 'Manage patterns' ) }\n\t\t\t</MenuItem>\n\t\t</>\n\t);\n}\n\nexport default PatternsManageButton;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAGO;AACP,kBAAmB;AACnB,oBAAgC;AAChC,kBAAuC;AACvC,qBAAyB;AACzB,0BAA0C;AAC1C,iBAA6B;AAC7B,uBAAmC;AAKnC,mBAAuC;AACvC,yBAAuB;AA6FnB;AA3FJ,SAAS,qBAAsB,EAAE,UAAU,QAAQ,GAAI;AACtD,QAAM,CAAE,mBAAmB,oBAAqB,QAAI,yBAAU,KAAM;AAEpE,QAAM;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,QAAI;AAAA,IACH,CAAE,WAAY;AACb,YAAM,EAAE,gBAAgB,UAAU,aAAa,IAC9C,OAAQ,oBAAAA,KAAiB;AAC1B,YAAM,EAAE,QAAQ,IAAI,OAAQ,iBAAAC,KAAU;AACtC,YAAM,QAAQ,SAAU,QAAS;AAEjC,YAAM,qBACL,CAAC,CAAE,OAAO,YAAY,UAAU;AAEjC,YAAM,mBACL,CAAC,CAAE,aACH,+BAAiB,KAAM,KACvB,CAAC,CAAE,QAAS,UAAU;AAAA,QACrB,MAAM;AAAA,QACN,MAAM;AAAA,QACN,IAAI,MAAM,WAAW;AAAA,MACtB,CAAE;AAEH,aAAO;AAAA,QACN,YAAY,MAAM;AAAA,QAClB,SAAS,aAAc,QAAS;AAAA;AAAA;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AAI,iBAAkB;AAAA,UAE1B,0BAA2B;AAAA,UAEzB,gCACC;AAAA,YACA;AAAA,UACA,QACA;AAAA,YACA;AAAA,UACA;AAAA;AAAA,MACJ;AAAA,OACD;AAAA,IAED,4CAAC,8BAAS,MAAO,mBACd,8BAAI,iBAAkB,GACzB;AAAA,KACD;AAEF;AAEA,IAAO,iCAAQ;",
|
|
6
|
+
"names": ["blockEditorStore", "coreStore", "patternsStore", "ConfirmDialog"]
|
|
7
7
|
}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
// packages/patterns/src/components/patterns-manage-button.js
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
MenuItem,
|
|
4
|
+
__experimentalConfirmDialog as ConfirmDialog
|
|
5
|
+
} from "@wordpress/components";
|
|
3
6
|
import { __ } from "@wordpress/i18n";
|
|
4
7
|
import { isReusableBlock } from "@wordpress/blocks";
|
|
5
8
|
import { useSelect, useDispatch } from "@wordpress/data";
|
|
9
|
+
import { useState } from "@wordpress/element";
|
|
6
10
|
import { store as blockEditorStore } from "@wordpress/block-editor";
|
|
7
11
|
import { addQueryArgs } from "@wordpress/url";
|
|
8
12
|
import { store as coreStore } from "@wordpress/core-data";
|
|
@@ -10,6 +14,7 @@ import { store as patternsStore } from "../store/index.mjs";
|
|
|
10
14
|
import { unlock } from "../lock-unlock.mjs";
|
|
11
15
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
12
16
|
function PatternsManageButton({ clientId, onClose }) {
|
|
17
|
+
const [showConfirmDialog, setShowConfirmDialog] = useState(false);
|
|
13
18
|
const {
|
|
14
19
|
attributes,
|
|
15
20
|
canDetach,
|
|
@@ -61,28 +66,40 @@ function PatternsManageButton({ clientId, onClose }) {
|
|
|
61
66
|
if (!isVisible || !canEdit) {
|
|
62
67
|
return null;
|
|
63
68
|
}
|
|
69
|
+
const handleDetach = () => {
|
|
70
|
+
if (isSyncedPattern) {
|
|
71
|
+
convertSyncedPatternToStatic(clientId);
|
|
72
|
+
}
|
|
73
|
+
if (isUnsyncedPattern) {
|
|
74
|
+
const { patternName, ...attributesWithoutPatternName } = attributes?.metadata ?? {};
|
|
75
|
+
updateBlockAttributes(clientId, {
|
|
76
|
+
metadata: attributesWithoutPatternName
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
onClose?.();
|
|
80
|
+
setShowConfirmDialog(false);
|
|
81
|
+
};
|
|
64
82
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
65
|
-
canDetach && /* @__PURE__ */
|
|
66
|
-
MenuItem,
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
),
|
|
83
|
+
canDetach && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
84
|
+
/* @__PURE__ */ jsx(MenuItem, { onClick: () => setShowConfirmDialog(true), children: isSyncedPattern ? __("Disconnect pattern") : __("Detach pattern") }),
|
|
85
|
+
/* @__PURE__ */ jsx(
|
|
86
|
+
ConfirmDialog,
|
|
87
|
+
{
|
|
88
|
+
isOpen: showConfirmDialog,
|
|
89
|
+
onConfirm: handleDetach,
|
|
90
|
+
onCancel: () => setShowConfirmDialog(false),
|
|
91
|
+
confirmButtonText: isSyncedPattern ? __("Disconnect") : __("Detach"),
|
|
92
|
+
size: "medium",
|
|
93
|
+
title: isSyncedPattern ? __("Disconnect pattern?") : __("Detach pattern?"),
|
|
94
|
+
__experimentalHideHeader: false,
|
|
95
|
+
children: isSyncedPattern ? __(
|
|
96
|
+
"The blocks will be separated from the original pattern and will be fully editable. Future changes to the pattern will not apply here."
|
|
97
|
+
) : __(
|
|
98
|
+
"Blocks will no longer be associated with this pattern and will be fully editable."
|
|
99
|
+
)
|
|
100
|
+
}
|
|
101
|
+
)
|
|
102
|
+
] }),
|
|
86
103
|
/* @__PURE__ */ jsx(MenuItem, { href: managePatternsUrl, children: __("Manage patterns") })
|
|
87
104
|
] });
|
|
88
105
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/components/patterns-manage-button.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {
|
|
5
|
-
"mappings": ";AAGA,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tMenuItem,\n\t__experimentalConfirmDialog as ConfirmDialog,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { isReusableBlock } from '@wordpress/blocks';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useState } from '@wordpress/element';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { addQueryArgs } from '@wordpress/url';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as patternsStore } from '../store';\nimport { unlock } from '../lock-unlock';\n\nfunction PatternsManageButton( { clientId, onClose } ) {\n\tconst [ showConfirmDialog, setShowConfirmDialog ] = useState( false );\n\n\tconst {\n\t\tattributes,\n\t\tcanDetach,\n\t\tisVisible,\n\t\tmanagePatternsUrl,\n\t\tisSyncedPattern,\n\t\tisUnsyncedPattern,\n\t\tcanEdit,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst { canRemoveBlock, getBlock, canEditBlock } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst { canUser } = select( coreStore );\n\t\t\tconst block = getBlock( clientId );\n\n\t\t\tconst _isUnsyncedPattern =\n\t\t\t\t!! block?.attributes?.metadata?.patternName;\n\n\t\t\tconst _isSyncedPattern =\n\t\t\t\t!! block &&\n\t\t\t\tisReusableBlock( block ) &&\n\t\t\t\t!! canUser( 'update', {\n\t\t\t\t\tkind: 'postType',\n\t\t\t\t\tname: 'wp_block',\n\t\t\t\t\tid: block.attributes.ref,\n\t\t\t\t} );\n\n\t\t\treturn {\n\t\t\t\tattributes: block.attributes,\n\t\t\t\tcanEdit: canEditBlock( clientId ),\n\t\t\t\t// For unsynced patterns, detaching is simply removing the `patternName` attribute.\n\t\t\t\t// For synced patterns, the `core:block` block is replaced with its inner blocks,\n\t\t\t\t// so checking whether `canRemoveBlock` is possible is required.\n\t\t\t\tcanDetach:\n\t\t\t\t\t_isUnsyncedPattern ||\n\t\t\t\t\t( _isSyncedPattern && canRemoveBlock( clientId ) ),\n\t\t\t\tisUnsyncedPattern: _isUnsyncedPattern,\n\t\t\t\tisSyncedPattern: _isSyncedPattern,\n\t\t\t\tisVisible: _isUnsyncedPattern || _isSyncedPattern,\n\t\t\t\t// The site editor and templates both check whether the user\n\t\t\t\t// has edit_theme_options capabilities. We can leverage that here\n\t\t\t\t// and omit the manage patterns link if the user can't access it.\n\t\t\t\tmanagePatternsUrl: canUser( 'create', {\n\t\t\t\t\tkind: 'postType',\n\t\t\t\t\tname: 'wp_template',\n\t\t\t\t} )\n\t\t\t\t\t? addQueryArgs( 'site-editor.php', {\n\t\t\t\t\t\t\tp: '/pattern',\n\t\t\t\t\t } )\n\t\t\t\t\t: addQueryArgs( 'edit.php', {\n\t\t\t\t\t\t\tpost_type: 'wp_block',\n\t\t\t\t\t } ),\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst { updateBlockAttributes } = useDispatch( blockEditorStore );\n\n\t// Ignore reason: false positive of the lint rule.\n\t// eslint-disable-next-line @wordpress/no-unused-vars-before-return\n\tconst { convertSyncedPatternToStatic } = unlock(\n\t\tuseDispatch( patternsStore )\n\t);\n\n\tif ( ! isVisible || ! canEdit ) {\n\t\treturn null;\n\t}\n\n\tconst handleDetach = () => {\n\t\tif ( isSyncedPattern ) {\n\t\t\tconvertSyncedPatternToStatic( clientId );\n\t\t}\n\n\t\tif ( isUnsyncedPattern ) {\n\t\t\tconst { patternName, ...attributesWithoutPatternName } =\n\t\t\t\tattributes?.metadata ?? {};\n\t\t\tupdateBlockAttributes( clientId, {\n\t\t\t\tmetadata: attributesWithoutPatternName,\n\t\t\t} );\n\t\t}\n\t\tonClose?.();\n\t\tsetShowConfirmDialog( false );\n\t};\n\n\treturn (\n\t\t<>\n\t\t\t{ canDetach && (\n\t\t\t\t<>\n\t\t\t\t\t<MenuItem onClick={ () => setShowConfirmDialog( true ) }>\n\t\t\t\t\t\t{ isSyncedPattern\n\t\t\t\t\t\t\t? __( 'Disconnect pattern' )\n\t\t\t\t\t\t\t: __( 'Detach pattern' ) }\n\t\t\t\t\t</MenuItem>\n\t\t\t\t\t<ConfirmDialog\n\t\t\t\t\t\tisOpen={ showConfirmDialog }\n\t\t\t\t\t\tonConfirm={ handleDetach }\n\t\t\t\t\t\tonCancel={ () => setShowConfirmDialog( false ) }\n\t\t\t\t\t\tconfirmButtonText={\n\t\t\t\t\t\t\tisSyncedPattern\n\t\t\t\t\t\t\t\t? __( 'Disconnect' )\n\t\t\t\t\t\t\t\t: __( 'Detach' )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsize=\"medium\"\n\t\t\t\t\t\ttitle={\n\t\t\t\t\t\t\tisSyncedPattern\n\t\t\t\t\t\t\t\t? __( 'Disconnect pattern?' )\n\t\t\t\t\t\t\t\t: __( 'Detach pattern?' )\n\t\t\t\t\t\t}\n\t\t\t\t\t\t__experimentalHideHeader={ false }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ isSyncedPattern\n\t\t\t\t\t\t\t? __(\n\t\t\t\t\t\t\t\t\t'The blocks will be separated from the original pattern and will be fully editable. Future changes to the pattern will not apply here.'\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: __(\n\t\t\t\t\t\t\t\t\t'Blocks will no longer be associated with this pattern and will be fully editable.'\n\t\t\t\t\t\t\t ) }\n\t\t\t\t\t</ConfirmDialog>\n\t\t\t\t</>\n\t\t\t) }\n\t\t\t<MenuItem href={ managePattern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;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/patterns",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.42.0",
|
|
4
4
|
"description": "Management of user pattern editing.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -52,21 +52,21 @@
|
|
|
52
52
|
"build-module/store/index.mjs"
|
|
53
53
|
],
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@wordpress/a11y": "^4.
|
|
56
|
-
"@wordpress/base-styles": "^6.
|
|
57
|
-
"@wordpress/block-editor": "^15.
|
|
58
|
-
"@wordpress/blocks": "^15.
|
|
59
|
-
"@wordpress/components": "^32.4.
|
|
60
|
-
"@wordpress/compose": "^7.
|
|
61
|
-
"@wordpress/core-data": "^7.
|
|
62
|
-
"@wordpress/data": "^10.
|
|
63
|
-
"@wordpress/element": "^6.
|
|
64
|
-
"@wordpress/html-entities": "^4.
|
|
65
|
-
"@wordpress/i18n": "^6.
|
|
66
|
-
"@wordpress/icons": "^12.0.
|
|
67
|
-
"@wordpress/notices": "^5.
|
|
68
|
-
"@wordpress/private-apis": "^1.
|
|
69
|
-
"@wordpress/url": "^4.
|
|
55
|
+
"@wordpress/a11y": "^4.42.0",
|
|
56
|
+
"@wordpress/base-styles": "^6.18.0",
|
|
57
|
+
"@wordpress/block-editor": "^15.15.0",
|
|
58
|
+
"@wordpress/blocks": "^15.15.0",
|
|
59
|
+
"@wordpress/components": "^32.4.0",
|
|
60
|
+
"@wordpress/compose": "^7.42.0",
|
|
61
|
+
"@wordpress/core-data": "^7.42.0",
|
|
62
|
+
"@wordpress/data": "^10.42.0",
|
|
63
|
+
"@wordpress/element": "^6.42.0",
|
|
64
|
+
"@wordpress/html-entities": "^4.42.0",
|
|
65
|
+
"@wordpress/i18n": "^6.15.0",
|
|
66
|
+
"@wordpress/icons": "^12.0.0",
|
|
67
|
+
"@wordpress/notices": "^5.42.0",
|
|
68
|
+
"@wordpress/private-apis": "^1.42.0",
|
|
69
|
+
"@wordpress/url": "^4.42.0"
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|
|
72
72
|
"react": "^18.0.0",
|
|
@@ -75,5 +75,5 @@
|
|
|
75
75
|
"publishConfig": {
|
|
76
76
|
"access": "public"
|
|
77
77
|
},
|
|
78
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "c20787b1778ae64c2db65643b1c236309d68e6ba"
|
|
79
79
|
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
MenuItem,
|
|
6
|
+
__experimentalConfirmDialog as ConfirmDialog,
|
|
7
|
+
} from '@wordpress/components';
|
|
5
8
|
import { __ } from '@wordpress/i18n';
|
|
6
9
|
import { isReusableBlock } from '@wordpress/blocks';
|
|
7
10
|
import { useSelect, useDispatch } from '@wordpress/data';
|
|
11
|
+
import { useState } from '@wordpress/element';
|
|
8
12
|
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
9
13
|
import { addQueryArgs } from '@wordpress/url';
|
|
10
14
|
import { store as coreStore } from '@wordpress/core-data';
|
|
@@ -16,6 +20,8 @@ import { store as patternsStore } from '../store';
|
|
|
16
20
|
import { unlock } from '../lock-unlock';
|
|
17
21
|
|
|
18
22
|
function PatternsManageButton( { clientId, onClose } ) {
|
|
23
|
+
const [ showConfirmDialog, setShowConfirmDialog ] = useState( false );
|
|
24
|
+
|
|
19
25
|
const {
|
|
20
26
|
attributes,
|
|
21
27
|
canDetach,
|
|
@@ -85,31 +91,57 @@ function PatternsManageButton( { clientId, onClose } ) {
|
|
|
85
91
|
return null;
|
|
86
92
|
}
|
|
87
93
|
|
|
94
|
+
const handleDetach = () => {
|
|
95
|
+
if ( isSyncedPattern ) {
|
|
96
|
+
convertSyncedPatternToStatic( clientId );
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if ( isUnsyncedPattern ) {
|
|
100
|
+
const { patternName, ...attributesWithoutPatternName } =
|
|
101
|
+
attributes?.metadata ?? {};
|
|
102
|
+
updateBlockAttributes( clientId, {
|
|
103
|
+
metadata: attributesWithoutPatternName,
|
|
104
|
+
} );
|
|
105
|
+
}
|
|
106
|
+
onClose?.();
|
|
107
|
+
setShowConfirmDialog( false );
|
|
108
|
+
};
|
|
109
|
+
|
|
88
110
|
return (
|
|
89
111
|
<>
|
|
90
112
|
{ canDetach && (
|
|
91
|
-
|
|
92
|
-
onClick={ () =>
|
|
93
|
-
|
|
94
|
-
|
|
113
|
+
<>
|
|
114
|
+
<MenuItem onClick={ () => setShowConfirmDialog( true ) }>
|
|
115
|
+
{ isSyncedPattern
|
|
116
|
+
? __( 'Disconnect pattern' )
|
|
117
|
+
: __( 'Detach pattern' ) }
|
|
118
|
+
</MenuItem>
|
|
119
|
+
<ConfirmDialog
|
|
120
|
+
isOpen={ showConfirmDialog }
|
|
121
|
+
onConfirm={ handleDetach }
|
|
122
|
+
onCancel={ () => setShowConfirmDialog( false ) }
|
|
123
|
+
confirmButtonText={
|
|
124
|
+
isSyncedPattern
|
|
125
|
+
? __( 'Disconnect' )
|
|
126
|
+
: __( 'Detach' )
|
|
95
127
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
} = attributes?.metadata ?? {};
|
|
102
|
-
updateBlockAttributes( clientId, {
|
|
103
|
-
metadata: attributesWithoutPatternName,
|
|
104
|
-
} );
|
|
128
|
+
size="medium"
|
|
129
|
+
title={
|
|
130
|
+
isSyncedPattern
|
|
131
|
+
? __( 'Disconnect pattern?' )
|
|
132
|
+
: __( 'Detach pattern?' )
|
|
105
133
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
134
|
+
__experimentalHideHeader={ false }
|
|
135
|
+
>
|
|
136
|
+
{ isSyncedPattern
|
|
137
|
+
? __(
|
|
138
|
+
'The blocks will be separated from the original pattern and will be fully editable. Future changes to the pattern will not apply here.'
|
|
139
|
+
)
|
|
140
|
+
: __(
|
|
141
|
+
'Blocks will no longer be associated with this pattern and will be fully editable.'
|
|
142
|
+
) }
|
|
143
|
+
</ConfirmDialog>
|
|
144
|
+
</>
|
|
113
145
|
) }
|
|
114
146
|
<MenuItem href={ managePatternsUrl }>
|
|
115
147
|
{ __( 'Manage patterns' ) }
|