@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,36 @@
|
|
|
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 patterns_manage_button_exports = {};
|
|
19
|
+
__export(patterns_manage_button_exports, {
|
|
20
|
+
default: () => patterns_manage_button_default
|
|
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
|
-
|
|
18
|
-
* WordPress dependencies
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Internal dependencies
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
function PatternsManageButton({
|
|
26
|
-
clientId
|
|
27
|
-
}) {
|
|
22
|
+
module.exports = __toCommonJS(patterns_manage_button_exports);
|
|
23
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
24
|
+
var import_components = require("@wordpress/components");
|
|
25
|
+
var import_i18n = require("@wordpress/i18n");
|
|
26
|
+
var import_blocks = require("@wordpress/blocks");
|
|
27
|
+
var import_data = require("@wordpress/data");
|
|
28
|
+
var import_block_editor = require("@wordpress/block-editor");
|
|
29
|
+
var import_url = require("@wordpress/url");
|
|
30
|
+
var import_core_data = require("@wordpress/core-data");
|
|
31
|
+
var import_store = require("../store");
|
|
32
|
+
var import_lock_unlock = require("../lock-unlock");
|
|
33
|
+
function PatternsManageButton({ clientId }) {
|
|
28
34
|
const {
|
|
29
35
|
attributes,
|
|
30
36
|
canDetach,
|
|
@@ -32,78 +38,71 @@ function PatternsManageButton({
|
|
|
32
38
|
managePatternsUrl,
|
|
33
39
|
isSyncedPattern,
|
|
34
40
|
isUnsyncedPattern
|
|
35
|
-
} = (0,
|
|
36
|
-
|
|
37
|
-
canRemoveBlock,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
canUser
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
} = (0, _data.useDispatch)(_blockEditor.store);
|
|
75
|
-
|
|
76
|
-
// Ignore reason: false positive of the lint rule.
|
|
77
|
-
// eslint-disable-next-line @wordpress/no-unused-vars-before-return
|
|
78
|
-
const {
|
|
79
|
-
convertSyncedPatternToStatic
|
|
80
|
-
} = (0, _lockUnlock.unlock)((0, _data.useDispatch)(_store.store));
|
|
41
|
+
} = (0, import_data.useSelect)(
|
|
42
|
+
(select) => {
|
|
43
|
+
const { canRemoveBlock, getBlock } = select(import_block_editor.store);
|
|
44
|
+
const { canUser } = select(import_core_data.store);
|
|
45
|
+
const block = getBlock(clientId);
|
|
46
|
+
const _isUnsyncedPattern = window?.__experimentalContentOnlyPatternInsertion && !!block?.attributes?.metadata?.patternName;
|
|
47
|
+
const _isSyncedPattern = !!block && (0, import_blocks.isReusableBlock)(block) && !!canUser("update", {
|
|
48
|
+
kind: "postType",
|
|
49
|
+
name: "wp_block",
|
|
50
|
+
id: block.attributes.ref
|
|
51
|
+
});
|
|
52
|
+
return {
|
|
53
|
+
attributes: block.attributes,
|
|
54
|
+
// For unsynced patterns, detaching is simply removing the `patternName` attribute.
|
|
55
|
+
// For synced patterns, the `core:block` block is replaced with its inner blocks,
|
|
56
|
+
// so checking whether `canRemoveBlock` is possible is required.
|
|
57
|
+
canDetach: _isUnsyncedPattern || _isSyncedPattern && canRemoveBlock(clientId),
|
|
58
|
+
isUnsyncedPattern: _isUnsyncedPattern,
|
|
59
|
+
isSyncedPattern: _isSyncedPattern,
|
|
60
|
+
isVisible: _isUnsyncedPattern || _isSyncedPattern,
|
|
61
|
+
// The site editor and templates both check whether the user
|
|
62
|
+
// has edit_theme_options capabilities. We can leverage that here
|
|
63
|
+
// and omit the manage patterns link if the user can't access it.
|
|
64
|
+
managePatternsUrl: canUser("create", {
|
|
65
|
+
kind: "postType",
|
|
66
|
+
name: "wp_template"
|
|
67
|
+
}) ? (0, import_url.addQueryArgs)("site-editor.php", {
|
|
68
|
+
p: "/pattern"
|
|
69
|
+
}) : (0, import_url.addQueryArgs)("edit.php", {
|
|
70
|
+
post_type: "wp_block"
|
|
71
|
+
})
|
|
72
|
+
};
|
|
73
|
+
},
|
|
74
|
+
[clientId]
|
|
75
|
+
);
|
|
76
|
+
const { updateBlockAttributes } = (0, import_data.useDispatch)(import_block_editor.store);
|
|
77
|
+
const { convertSyncedPatternToStatic } = (0, import_lock_unlock.unlock)(
|
|
78
|
+
(0, import_data.useDispatch)(import_store.store)
|
|
79
|
+
);
|
|
81
80
|
if (!isVisible) {
|
|
82
81
|
return null;
|
|
83
82
|
}
|
|
84
|
-
return
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
})
|
|
106
|
-
});
|
|
83
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
84
|
+
canDetach && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
85
|
+
import_components.MenuItem,
|
|
86
|
+
{
|
|
87
|
+
onClick: () => {
|
|
88
|
+
if (isSyncedPattern) {
|
|
89
|
+
convertSyncedPatternToStatic(clientId);
|
|
90
|
+
}
|
|
91
|
+
if (isUnsyncedPattern) {
|
|
92
|
+
const {
|
|
93
|
+
patternName,
|
|
94
|
+
...attributesWithoutPatternName
|
|
95
|
+
} = attributes?.metadata ?? {};
|
|
96
|
+
updateBlockAttributes(clientId, {
|
|
97
|
+
metadata: attributesWithoutPatternName
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
children: (0, import_i18n.__)("Detach")
|
|
102
|
+
}
|
|
103
|
+
),
|
|
104
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.MenuItem, { href: managePatternsUrl, children: (0, import_i18n.__)("Manage patterns") })
|
|
105
|
+
] });
|
|
107
106
|
}
|
|
108
|
-
var
|
|
109
|
-
//# sourceMappingURL=patterns-manage-button.js.map
|
|
107
|
+
var patterns_manage_button_default = PatternsManageButton;
|
|
108
|
+
//# sourceMappingURL=patterns-manage-button.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/components/patterns-manage-button.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { MenuItem } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { isReusableBlock } from '@wordpress/blocks';\nimport { useSelect, useDispatch } from '@wordpress/data';\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 } ) {\n\tconst {\n\t\tattributes,\n\t\tcanDetach,\n\t\tisVisible,\n\t\tmanagePatternsUrl,\n\t\tisSyncedPattern,\n\t\tisUnsyncedPattern,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst { canRemoveBlock, getBlock } = select( 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\twindow?.__experimentalContentOnlyPatternInsertion &&\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\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 ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ canDetach && (\n\t\t\t\t<MenuItem\n\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\tif ( isSyncedPattern ) {\n\t\t\t\t\t\t\tconvertSyncedPatternToStatic( clientId );\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif ( isUnsyncedPattern ) {\n\t\t\t\t\t\t\tconst {\n\t\t\t\t\t\t\t\tpatternName,\n\t\t\t\t\t\t\t\t...attributesWithoutPatternName\n\t\t\t\t\t\t\t} = attributes?.metadata ?? {};\n\t\t\t\t\t\t\tupdateBlockAttributes( clientId, {\n\t\t\t\t\t\t\t\tmetadata: attributesWithoutPatternName,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t}\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Detach' ) }\n\t\t\t\t</MenuItem>\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;AAsFE;AAnFF,wBAAyB;AACzB,kBAAmB;AACnB,oBAAgC;AAChC,kBAAuC;AACvC,0BAA0C;AAC1C,iBAA6B;AAC7B,uBAAmC;AAKnC,mBAAuC;AACvC,yBAAuB;AAEvB,SAAS,qBAAsB,EAAE,SAAS,GAAI;AAC7C,QAAM;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,QAAI;AAAA,IACH,CAAE,WAAY;AACb,YAAM,EAAE,gBAAgB,SAAS,IAAI,OAAQ,oBAAAA,KAAiB;AAC9D,YAAM,EAAE,QAAQ,IAAI,OAAQ,iBAAAC,KAAU;AACtC,YAAM,QAAQ,SAAU,QAAS;AAEjC,YAAM,qBACL,QAAQ,6CACR,CAAC,CAAE,OAAO,YAAY,UAAU;AAEjC,YAAM,mBACL,CAAC,CAAE,aACH,+BAAiB,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}
|
|
@@ -1,27 +1,35 @@
|
|
|
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 rename_pattern_category_modal_exports = {};
|
|
19
|
+
__export(rename_pattern_category_modal_exports, {
|
|
20
|
+
default: () => RenamePatternCategoryModal
|
|
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
|
-
/**
|
|
18
|
-
* WordPress dependencies
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Internal dependencies
|
|
23
|
-
*/
|
|
24
|
-
|
|
22
|
+
module.exports = __toCommonJS(rename_pattern_category_modal_exports);
|
|
23
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
24
|
+
var import_components = require("@wordpress/components");
|
|
25
|
+
var import_core_data = require("@wordpress/core-data");
|
|
26
|
+
var import_data = require("@wordpress/data");
|
|
27
|
+
var import_element = require("@wordpress/element");
|
|
28
|
+
var import_html_entities = require("@wordpress/html-entities");
|
|
29
|
+
var import_i18n = require("@wordpress/i18n");
|
|
30
|
+
var import_notices = require("@wordpress/notices");
|
|
31
|
+
var import_a11y = require("@wordpress/a11y");
|
|
32
|
+
var import_category_selector = require("./category-selector");
|
|
25
33
|
function RenamePatternCategoryModal({
|
|
26
34
|
category,
|
|
27
35
|
existingCategories,
|
|
@@ -30,127 +38,130 @@ function RenamePatternCategoryModal({
|
|
|
30
38
|
onSuccess,
|
|
31
39
|
...props
|
|
32
40
|
}) {
|
|
33
|
-
const id = (0,
|
|
34
|
-
const textControlRef = (0,
|
|
35
|
-
const [name, setName] = (0,
|
|
36
|
-
const [isSaving, setIsSaving] = (0,
|
|
37
|
-
const [validationMessage, setValidationMessage] = (0,
|
|
38
|
-
const validationMessageId = validationMessage ? `patterns-rename-pattern-category-modal__validation-message-${id}` :
|
|
39
|
-
const {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
} = (0, _data.useDispatch)(_coreData.store);
|
|
43
|
-
const {
|
|
44
|
-
createErrorNotice,
|
|
45
|
-
createSuccessNotice
|
|
46
|
-
} = (0, _data.useDispatch)(_notices.store);
|
|
47
|
-
const onChange = newName => {
|
|
41
|
+
const id = (0, import_element.useId)();
|
|
42
|
+
const textControlRef = (0, import_element.useRef)();
|
|
43
|
+
const [name, setName] = (0, import_element.useState)((0, import_html_entities.decodeEntities)(category.name));
|
|
44
|
+
const [isSaving, setIsSaving] = (0, import_element.useState)(false);
|
|
45
|
+
const [validationMessage, setValidationMessage] = (0, import_element.useState)(false);
|
|
46
|
+
const validationMessageId = validationMessage ? `patterns-rename-pattern-category-modal__validation-message-${id}` : void 0;
|
|
47
|
+
const { saveEntityRecord, invalidateResolution } = (0, import_data.useDispatch)(import_core_data.store);
|
|
48
|
+
const { createErrorNotice, createSuccessNotice } = (0, import_data.useDispatch)(import_notices.store);
|
|
49
|
+
const onChange = (newName) => {
|
|
48
50
|
if (validationMessage) {
|
|
49
|
-
setValidationMessage(
|
|
51
|
+
setValidationMessage(void 0);
|
|
50
52
|
}
|
|
51
53
|
setName(newName);
|
|
52
54
|
};
|
|
53
|
-
const onSave = async event => {
|
|
55
|
+
const onSave = async (event) => {
|
|
54
56
|
event.preventDefault();
|
|
55
57
|
if (isSaving) {
|
|
56
58
|
return;
|
|
57
59
|
}
|
|
58
60
|
if (!name || name === category.name) {
|
|
59
|
-
const message = (0,
|
|
60
|
-
(0,
|
|
61
|
+
const message = (0, import_i18n.__)("Please enter a new name for this category.");
|
|
62
|
+
(0, import_a11y.speak)(message, "assertive");
|
|
61
63
|
setValidationMessage(message);
|
|
62
64
|
textControlRef.current?.focus();
|
|
63
65
|
return;
|
|
64
66
|
}
|
|
65
|
-
|
|
66
|
-
// Check existing categories to avoid creating duplicates.
|
|
67
|
-
if (existingCategories.patternCategories.find(existingCategory => {
|
|
68
|
-
// Compare the id so that the we don't disallow the user changing the case of their current category
|
|
69
|
-
// (i.e. renaming 'test' to 'Test').
|
|
67
|
+
if (existingCategories.patternCategories.find((existingCategory) => {
|
|
70
68
|
return existingCategory.id !== category.id && existingCategory.label.toLowerCase() === name.toLowerCase();
|
|
71
69
|
})) {
|
|
72
|
-
const message = (0,
|
|
73
|
-
|
|
70
|
+
const message = (0, import_i18n.__)(
|
|
71
|
+
"This category already exists. Please use a different name."
|
|
72
|
+
);
|
|
73
|
+
(0, import_a11y.speak)(message, "assertive");
|
|
74
74
|
setValidationMessage(message);
|
|
75
75
|
textControlRef.current?.focus();
|
|
76
76
|
return;
|
|
77
77
|
}
|
|
78
78
|
try {
|
|
79
79
|
setIsSaving(true);
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
invalidateResolution('getUserPatternCategories');
|
|
80
|
+
const savedRecord = await saveEntityRecord(
|
|
81
|
+
"taxonomy",
|
|
82
|
+
import_category_selector.CATEGORY_SLUG,
|
|
83
|
+
{
|
|
84
|
+
id: category.id,
|
|
85
|
+
slug: category.slug,
|
|
86
|
+
name
|
|
87
|
+
}
|
|
88
|
+
);
|
|
89
|
+
invalidateResolution("getUserPatternCategories");
|
|
91
90
|
onSuccess?.(savedRecord);
|
|
92
91
|
onClose();
|
|
93
|
-
createSuccessNotice((0,
|
|
94
|
-
type:
|
|
95
|
-
id:
|
|
92
|
+
createSuccessNotice((0, import_i18n.__)("Pattern category renamed."), {
|
|
93
|
+
type: "snackbar",
|
|
94
|
+
id: "pattern-category-update"
|
|
96
95
|
});
|
|
97
96
|
} catch (error) {
|
|
98
97
|
onError?.();
|
|
99
98
|
createErrorNotice(error.message, {
|
|
100
|
-
type:
|
|
101
|
-
id:
|
|
99
|
+
type: "snackbar",
|
|
100
|
+
id: "pattern-category-update"
|
|
102
101
|
});
|
|
103
102
|
} finally {
|
|
104
103
|
setIsSaving(false);
|
|
105
|
-
setName(
|
|
104
|
+
setName("");
|
|
106
105
|
}
|
|
107
106
|
};
|
|
108
107
|
const onRequestClose = () => {
|
|
109
108
|
onClose();
|
|
110
|
-
setName(
|
|
109
|
+
setName("");
|
|
111
110
|
};
|
|
112
|
-
return
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
children:
|
|
119
|
-
spacing: "
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
111
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
112
|
+
import_components.Modal,
|
|
113
|
+
{
|
|
114
|
+
title: (0, import_i18n.__)("Rename"),
|
|
115
|
+
onRequestClose,
|
|
116
|
+
...props,
|
|
117
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("form", { onSubmit: onSave, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalVStack, { spacing: "5", children: [
|
|
118
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalVStack, { spacing: "2", children: [
|
|
119
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
120
|
+
import_components.TextControl,
|
|
121
|
+
{
|
|
122
|
+
ref: textControlRef,
|
|
123
|
+
__nextHasNoMarginBottom: true,
|
|
124
|
+
__next40pxDefaultSize: true,
|
|
125
|
+
label: (0, import_i18n.__)("Name"),
|
|
126
|
+
value: name,
|
|
127
|
+
onChange,
|
|
128
|
+
"aria-describedby": validationMessageId,
|
|
129
|
+
required: true
|
|
130
|
+
}
|
|
131
|
+
),
|
|
132
|
+
validationMessage && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
133
|
+
"span",
|
|
134
|
+
{
|
|
135
|
+
className: "patterns-rename-pattern-category-modal__validation-message",
|
|
136
|
+
id: validationMessageId,
|
|
137
|
+
children: validationMessage
|
|
138
|
+
}
|
|
139
|
+
)
|
|
140
|
+
] }),
|
|
141
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalHStack, { justify: "right", children: [
|
|
142
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
143
|
+
import_components.Button,
|
|
144
|
+
{
|
|
145
|
+
__next40pxDefaultSize: true,
|
|
146
|
+
variant: "tertiary",
|
|
147
|
+
onClick: onRequestClose,
|
|
148
|
+
children: (0, import_i18n.__)("Cancel")
|
|
149
|
+
}
|
|
150
|
+
),
|
|
151
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
152
|
+
import_components.Button,
|
|
153
|
+
{
|
|
154
|
+
__next40pxDefaultSize: true,
|
|
155
|
+
variant: "primary",
|
|
156
|
+
type: "submit",
|
|
157
|
+
"aria-disabled": !name || name === category.name || isSaving,
|
|
158
|
+
isBusy: isSaving,
|
|
159
|
+
children: (0, import_i18n.__)("Save")
|
|
160
|
+
}
|
|
161
|
+
)
|
|
162
|
+
] })
|
|
163
|
+
] }) })
|
|
164
|
+
}
|
|
165
|
+
);
|
|
155
166
|
}
|
|
156
|
-
//# sourceMappingURL=rename-pattern-category-modal.js.map
|
|
167
|
+
//# sourceMappingURL=rename-pattern-category-modal.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{"version":3,"names":["_components","require","_coreData","_data","_element","_htmlEntities","_i18n","_notices","_a11y","_categorySelector","_jsxRuntime","RenamePatternCategoryModal","category","existingCategories","onClose","onError","onSuccess","props","id","useId","textControlRef","useRef","name","setName","useState","decodeEntities","isSaving","setIsSaving","validationMessage","setValidationMessage","validationMessageId","undefined","saveEntityRecord","invalidateResolution","useDispatch","coreStore","createErrorNotice","createSuccessNotice","noticesStore","onChange","newName","onSave","event","preventDefault","message","__","speak","current","focus","patternCategories","find","existingCategory","label","toLowerCase","savedRecord","CATEGORY_SLUG","slug","type","error","onRequestClose","jsx","Modal","title","children","onSubmit","jsxs","__experimentalVStack","spacing","TextControl","ref","__nextHasNoMarginBottom","__next40pxDefaultSize","value","required","className","__experimentalHStack","justify","Button","variant","onClick","isBusy"],"sources":["@wordpress/patterns/src/components/rename-pattern-category-modal.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tModal,\n\tButton,\n\tTextControl,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useDispatch } from '@wordpress/data';\nimport { useId, useRef, useState } from '@wordpress/element';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { __ } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport { CATEGORY_SLUG } from './category-selector';\n\nexport default function RenamePatternCategoryModal( {\n\tcategory,\n\texistingCategories,\n\tonClose,\n\tonError,\n\tonSuccess,\n\t...props\n} ) {\n\tconst id = useId();\n\tconst textControlRef = useRef();\n\tconst [ name, setName ] = useState( decodeEntities( category.name ) );\n\tconst [ isSaving, setIsSaving ] = useState( false );\n\tconst [ validationMessage, setValidationMessage ] = useState( false );\n\tconst validationMessageId = validationMessage\n\t\t? `patterns-rename-pattern-category-modal__validation-message-${ id }`\n\t\t: undefined;\n\n\tconst { saveEntityRecord, invalidateResolution } = useDispatch( coreStore );\n\tconst { createErrorNotice, createSuccessNotice } =\n\t\tuseDispatch( noticesStore );\n\n\tconst onChange = ( newName ) => {\n\t\tif ( validationMessage ) {\n\t\t\tsetValidationMessage( undefined );\n\t\t}\n\t\tsetName( newName );\n\t};\n\n\tconst onSave = async ( event ) => {\n\t\tevent.preventDefault();\n\n\t\tif ( isSaving ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( ! name || name === category.name ) {\n\t\t\tconst message = __( 'Please enter a new name for this category.' );\n\t\t\tspeak( message, 'assertive' );\n\t\t\tsetValidationMessage( message );\n\t\t\ttextControlRef.current?.focus();\n\t\t\treturn;\n\t\t}\n\n\t\t// Check existing categories to avoid creating duplicates.\n\t\tif (\n\t\t\texistingCategories.patternCategories.find( ( existingCategory ) => {\n\t\t\t\t// Compare the id so that the we don't disallow the user changing the case of their current category\n\t\t\t\t// (i.e. renaming 'test' to 'Test').\n\t\t\t\treturn (\n\t\t\t\t\texistingCategory.id !== category.id &&\n\t\t\t\t\texistingCategory.label.toLowerCase() === name.toLowerCase()\n\t\t\t\t);\n\t\t\t} )\n\t\t) {\n\t\t\tconst message = __(\n\t\t\t\t'This category already exists. Please use a different name.'\n\t\t\t);\n\t\t\tspeak( message, 'assertive' );\n\t\t\tsetValidationMessage( message );\n\t\t\ttextControlRef.current?.focus();\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tsetIsSaving( true );\n\n\t\t\t// User pattern category properties may differ as they can be\n\t\t\t// normalized for use alongside template part areas, core pattern\n\t\t\t// categories etc. As a result we won't just destructure the passed\n\t\t\t// category object.\n\t\t\tconst savedRecord = await saveEntityRecord(\n\t\t\t\t'taxonomy',\n\t\t\t\tCATEGORY_SLUG,\n\t\t\t\t{\n\t\t\t\t\tid: category.id,\n\t\t\t\t\tslug: category.slug,\n\t\t\t\t\tname,\n\t\t\t\t}\n\t\t\t);\n\n\t\t\tinvalidateResolution( 'getUserPatternCategories' );\n\t\t\tonSuccess?.( savedRecord );\n\t\t\tonClose();\n\n\t\t\tcreateSuccessNotice( __( 'Pattern category renamed.' ), {\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'pattern-category-update',\n\t\t\t} );\n\t\t} catch ( error ) {\n\t\t\tonError?.();\n\t\t\tcreateErrorNotice( error.message, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'pattern-category-update',\n\t\t\t} );\n\t\t} finally {\n\t\t\tsetIsSaving( false );\n\t\t\tsetName( '' );\n\t\t}\n\t};\n\n\tconst onRequestClose = () => {\n\t\tonClose();\n\t\tsetName( '' );\n\t};\n\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ __( 'Rename' ) }\n\t\t\tonRequestClose={ onRequestClose }\n\t\t\t{ ...props }\n\t\t>\n\t\t\t<form onSubmit={ onSave }>\n\t\t\t\t<VStack spacing=\"5\">\n\t\t\t\t\t<VStack spacing=\"2\">\n\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\tref={ textControlRef }\n\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\t\tvalue={ name }\n\t\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\t\taria-describedby={ validationMessageId }\n\t\t\t\t\t\t\trequired\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t{ validationMessage && (\n\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\tclassName=\"patterns-rename-pattern-category-modal__validation-message\"\n\t\t\t\t\t\t\t\tid={ validationMessageId }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ validationMessage }\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</VStack>\n\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ onRequestClose }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\taria-disabled={\n\t\t\t\t\t\t\t\t! name || name === category.name || isSaving\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tisBusy={ isSaving }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Save' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</HStack>\n\t\t\t\t</VStack>\n\t\t\t</form>\n\t\t</Modal>\n\t);\n}\n"],"mappings":";;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AAOA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,a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ACCc,SAAS,EAAC,4DAA4D;YACtExD,EAAE,EAAGY,mBAAqB;YAAAiC,QAAA,EAExBnC;UAAiB,CACd,CACN;QAAA,CACM,CAAC,eACT,IAAAlB,WAAA,CAAAuD,IAAA,EAACjE,WAAA,CAAA2E,oBAAM;UAACC,OAAO,EAAC,OAAO;UAAAb,QAAA,gBACtB,IAAArD,WAAA,CAAAkD,GAAA,EAAC5D,WAAA,CAAA6E,MAAM;YACNN,qBAAqB;YACrBO,OAAO,EAAC,UAAU;YAClBC,OAAO,EAAGpB,cAAgB;YAAAI,QAAA,EAExB,IAAAlB,QAAE,EAAE,QAAS;UAAC,CACT,CAAC,eACT,IAAAnC,WAAA,CAAAkD,GAAA,EAAC5D,WAAA,CAAA6E,MAAM;YACNN,qBAAqB;YACrBO,OAAO,EAAC,SAAS;YACjBrB,IAAI,EAAC,QAAQ;YACb,iBACC,CAAEnC,IAAI,IAAIA,IAAI,KAAKV,QAAQ,CAACU,IAAI,IAAII,QACpC;YACDsD,MAAM,EAAGtD,QAAU;YAAAqC,QAAA,EAEjB,IAAAlB,QAAE,EAAE,MAAO;UAAC,CACP,CAAC;QAAA,CACF,CAAC;MAAA,CACF;IAAC,CACJ;EAAC,CACD,CAAC;AAEV","ignoreList":[]}
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/components/rename-pattern-category-modal.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tModal,\n\tButton,\n\tTextControl,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useDispatch } from '@wordpress/data';\nimport { useId, useRef, useState } from '@wordpress/element';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { __ } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport { CATEGORY_SLUG } from './category-selector';\n\nexport default function RenamePatternCategoryModal( {\n\tcategory,\n\texistingCategories,\n\tonClose,\n\tonError,\n\tonSuccess,\n\t...props\n} ) {\n\tconst id = useId();\n\tconst textControlRef = useRef();\n\tconst [ name, setName ] = useState( decodeEntities( category.name ) );\n\tconst [ isSaving, setIsSaving ] = useState( false );\n\tconst [ validationMessage, setValidationMessage ] = useState( false );\n\tconst validationMessageId = validationMessage\n\t\t? `patterns-rename-pattern-category-modal__validation-message-${ id }`\n\t\t: undefined;\n\n\tconst { saveEntityRecord, invalidateResolution } = useDispatch( coreStore );\n\tconst { createErrorNotice, createSuccessNotice } =\n\t\tuseDispatch( noticesStore );\n\n\tconst onChange = ( newName ) => {\n\t\tif ( validationMessage ) {\n\t\t\tsetValidationMessage( undefined );\n\t\t}\n\t\tsetName( newName );\n\t};\n\n\tconst onSave = async ( event ) => {\n\t\tevent.preventDefault();\n\n\t\tif ( isSaving ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( ! name || name === category.name ) {\n\t\t\tconst message = __( 'Please enter a new name for this category.' );\n\t\t\tspeak( message, 'assertive' );\n\t\t\tsetValidationMessage( message );\n\t\t\ttextControlRef.current?.focus();\n\t\t\treturn;\n\t\t}\n\n\t\t// Check existing categories to avoid creating duplicates.\n\t\tif (\n\t\t\texistingCategories.patternCategories.find( ( existingCategory ) => {\n\t\t\t\t// Compare the id so that the we don't disallow the user changing the case of their current category\n\t\t\t\t// (i.e. renaming 'test' to 'Test').\n\t\t\t\treturn (\n\t\t\t\t\texistingCategory.id !== category.id &&\n\t\t\t\t\texistingCategory.label.toLowerCase() === name.toLowerCase()\n\t\t\t\t);\n\t\t\t} )\n\t\t) {\n\t\t\tconst message = __(\n\t\t\t\t'This category already exists. Please use a different name.'\n\t\t\t);\n\t\t\tspeak( message, 'assertive' );\n\t\t\tsetValidationMessage( message );\n\t\t\ttextControlRef.current?.focus();\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tsetIsSaving( true );\n\n\t\t\t// User pattern category properties may differ as they can be\n\t\t\t// normalized for use alongside template part areas, core pattern\n\t\t\t// categories etc. As a result we won't just destructure the passed\n\t\t\t// category object.\n\t\t\tconst savedRecord = await saveEntityRecord(\n\t\t\t\t'taxonomy',\n\t\t\t\tCATEGORY_SLUG,\n\t\t\t\t{\n\t\t\t\t\tid: category.id,\n\t\t\t\t\tslug: category.slug,\n\t\t\t\t\tname,\n\t\t\t\t}\n\t\t\t);\n\n\t\t\tinvalidateResolution( 'getUserPatternCategories' );\n\t\t\tonSuccess?.( savedRecord );\n\t\t\tonClose();\n\n\t\t\tcreateSuccessNotice( __( 'Pattern category renamed.' ), {\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'pattern-category-update',\n\t\t\t} );\n\t\t} catch ( error ) {\n\t\t\tonError?.();\n\t\t\tcreateErrorNotice( error.message, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'pattern-category-update',\n\t\t\t} );\n\t\t} finally {\n\t\t\tsetIsSaving( false );\n\t\t\tsetName( '' );\n\t\t}\n\t};\n\n\tconst onRequestClose = () => {\n\t\tonClose();\n\t\tsetName( '' );\n\t};\n\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ __( 'Rename' ) }\n\t\t\tonRequestClose={ onRequestClose }\n\t\t\t{ ...props }\n\t\t>\n\t\t\t<form onSubmit={ onSave }>\n\t\t\t\t<VStack spacing=\"5\">\n\t\t\t\t\t<VStack spacing=\"2\">\n\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\tref={ textControlRef }\n\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\t\tvalue={ name }\n\t\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\t\taria-describedby={ validationMessageId }\n\t\t\t\t\t\t\trequired\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t{ validationMessage && (\n\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\tclassName=\"patterns-rename-pattern-category-modal__validation-message\"\n\t\t\t\t\t\t\t\tid={ validationMessageId }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ validationMessage }\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</VStack>\n\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ onRequestClose }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\taria-disabled={\n\t\t\t\t\t\t\t\t! name || name === category.name || isSaving\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tisBusy={ isSaving }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Save' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</HStack>\n\t\t\t\t</VStack>\n\t\t\t</form>\n\t\t</Modal>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAwIK;AArIL,wBAMO;AACP,uBAAmC;AACnC,kBAA4B;AAC5B,qBAAwC;AACxC,2BAA+B;AAC/B,kBAAmB;AACnB,qBAAsC;AACtC,kBAAsB;AAKtB,+BAA8B;AAEf,SAAR,2BAA6C;AAAA,EACnD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACJ,GAAI;AACH,QAAM,SAAK,sBAAM;AACjB,QAAM,qBAAiB,uBAAO;AAC9B,QAAM,CAAE,MAAM,OAAQ,QAAI,6BAAU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