@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,23 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { store as
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Internal dependencies
|
|
14
|
-
*/
|
|
15
|
-
import { store as patternsStore } from '../store';
|
|
16
|
-
import { unlock } from '../lock-unlock';
|
|
17
|
-
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
18
|
-
function PatternsManageButton({
|
|
19
|
-
clientId
|
|
20
|
-
}) {
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { MenuItem } from "@wordpress/components";
|
|
3
|
+
import { __ } from "@wordpress/i18n";
|
|
4
|
+
import { isReusableBlock } from "@wordpress/blocks";
|
|
5
|
+
import { useSelect, useDispatch } from "@wordpress/data";
|
|
6
|
+
import { store as blockEditorStore } from "@wordpress/block-editor";
|
|
7
|
+
import { addQueryArgs } from "@wordpress/url";
|
|
8
|
+
import { store as coreStore } from "@wordpress/core-data";
|
|
9
|
+
import { store as patternsStore } from "../store";
|
|
10
|
+
import { unlock } from "../lock-unlock";
|
|
11
|
+
function PatternsManageButton({ clientId }) {
|
|
21
12
|
const {
|
|
22
13
|
attributes,
|
|
23
14
|
canDetach,
|
|
@@ -25,78 +16,74 @@ function PatternsManageButton({
|
|
|
25
16
|
managePatternsUrl,
|
|
26
17
|
isSyncedPattern,
|
|
27
18
|
isUnsyncedPattern
|
|
28
|
-
} = useSelect(
|
|
29
|
-
|
|
30
|
-
canRemoveBlock,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
canUser
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
} = useDispatch(blockEditorStore);
|
|
68
|
-
|
|
69
|
-
// Ignore reason: false positive of the lint rule.
|
|
70
|
-
// eslint-disable-next-line @wordpress/no-unused-vars-before-return
|
|
71
|
-
const {
|
|
72
|
-
convertSyncedPatternToStatic
|
|
73
|
-
} = unlock(useDispatch(patternsStore));
|
|
19
|
+
} = useSelect(
|
|
20
|
+
(select) => {
|
|
21
|
+
const { canRemoveBlock, getBlock } = select(blockEditorStore);
|
|
22
|
+
const { canUser } = select(coreStore);
|
|
23
|
+
const block = getBlock(clientId);
|
|
24
|
+
const _isUnsyncedPattern = window?.__experimentalContentOnlyPatternInsertion && !!block?.attributes?.metadata?.patternName;
|
|
25
|
+
const _isSyncedPattern = !!block && isReusableBlock(block) && !!canUser("update", {
|
|
26
|
+
kind: "postType",
|
|
27
|
+
name: "wp_block",
|
|
28
|
+
id: block.attributes.ref
|
|
29
|
+
});
|
|
30
|
+
return {
|
|
31
|
+
attributes: block.attributes,
|
|
32
|
+
// For unsynced patterns, detaching is simply removing the `patternName` attribute.
|
|
33
|
+
// For synced patterns, the `core:block` block is replaced with its inner blocks,
|
|
34
|
+
// so checking whether `canRemoveBlock` is possible is required.
|
|
35
|
+
canDetach: _isUnsyncedPattern || _isSyncedPattern && canRemoveBlock(clientId),
|
|
36
|
+
isUnsyncedPattern: _isUnsyncedPattern,
|
|
37
|
+
isSyncedPattern: _isSyncedPattern,
|
|
38
|
+
isVisible: _isUnsyncedPattern || _isSyncedPattern,
|
|
39
|
+
// The site editor and templates both check whether the user
|
|
40
|
+
// has edit_theme_options capabilities. We can leverage that here
|
|
41
|
+
// and omit the manage patterns link if the user can't access it.
|
|
42
|
+
managePatternsUrl: canUser("create", {
|
|
43
|
+
kind: "postType",
|
|
44
|
+
name: "wp_template"
|
|
45
|
+
}) ? addQueryArgs("site-editor.php", {
|
|
46
|
+
p: "/pattern"
|
|
47
|
+
}) : addQueryArgs("edit.php", {
|
|
48
|
+
post_type: "wp_block"
|
|
49
|
+
})
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
[clientId]
|
|
53
|
+
);
|
|
54
|
+
const { updateBlockAttributes } = useDispatch(blockEditorStore);
|
|
55
|
+
const { convertSyncedPatternToStatic } = unlock(
|
|
56
|
+
useDispatch(patternsStore)
|
|
57
|
+
);
|
|
74
58
|
if (!isVisible) {
|
|
75
59
|
return null;
|
|
76
60
|
}
|
|
77
|
-
return
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
})
|
|
99
|
-
});
|
|
61
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
62
|
+
canDetach && /* @__PURE__ */ jsx(
|
|
63
|
+
MenuItem,
|
|
64
|
+
{
|
|
65
|
+
onClick: () => {
|
|
66
|
+
if (isSyncedPattern) {
|
|
67
|
+
convertSyncedPatternToStatic(clientId);
|
|
68
|
+
}
|
|
69
|
+
if (isUnsyncedPattern) {
|
|
70
|
+
const {
|
|
71
|
+
patternName,
|
|
72
|
+
...attributesWithoutPatternName
|
|
73
|
+
} = attributes?.metadata ?? {};
|
|
74
|
+
updateBlockAttributes(clientId, {
|
|
75
|
+
metadata: attributesWithoutPatternName
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
children: __("Detach")
|
|
80
|
+
}
|
|
81
|
+
),
|
|
82
|
+
/* @__PURE__ */ jsx(MenuItem, { href: managePatternsUrl, children: __("Manage patterns") })
|
|
83
|
+
] });
|
|
100
84
|
}
|
|
101
|
-
|
|
102
|
-
|
|
85
|
+
var patterns_manage_button_default = PatternsManageButton;
|
|
86
|
+
export {
|
|
87
|
+
patterns_manage_button_default as default
|
|
88
|
+
};
|
|
89
|
+
//# 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": "AAsFE,mBAEE,KAFF;AAnFF,SAAS,gBAAgB;AACzB,SAAS,UAAU;AACnB,SAAS,uBAAuB;AAChC,SAAS,WAAW,mBAAmB;AACvC,SAAS,SAAS,wBAAwB;AAC1C,SAAS,oBAAoB;AAC7B,SAAS,SAAS,iBAAiB;AAKnC,SAAS,SAAS,qBAAqB;AACvC,SAAS,cAAc;AAEvB,SAAS,qBAAsB,EAAE,SAAS,GAAI;AAC7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AAAA,cACA,GAAG;AAAA,YACJ,IAAI,YAAY,YAAY,CAAC;AAC7B,kCAAuB,UAAU;AAAA,cAChC,UAAU;AAAA,YACX,CAAE;AAAA,UACH;AAAA,QACD;AAAA,QAEE,aAAI,QAAS;AAAA;AAAA,IAChB;AAAA,IAED,oBAAC,YAAS,MAAO,mBACd,aAAI,iBAAkB,GACzB;AAAA,KACD;AAEF;AAEA,IAAO,iCAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
import { CATEGORY_SLUG } from
|
|
17
|
-
|
|
18
|
-
export default function RenamePatternCategoryModal({
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import {
|
|
3
|
+
Modal,
|
|
4
|
+
Button,
|
|
5
|
+
TextControl,
|
|
6
|
+
__experimentalHStack as HStack,
|
|
7
|
+
__experimentalVStack as VStack
|
|
8
|
+
} from "@wordpress/components";
|
|
9
|
+
import { store as coreStore } from "@wordpress/core-data";
|
|
10
|
+
import { useDispatch } from "@wordpress/data";
|
|
11
|
+
import { useId, useRef, useState } from "@wordpress/element";
|
|
12
|
+
import { decodeEntities } from "@wordpress/html-entities";
|
|
13
|
+
import { __ } from "@wordpress/i18n";
|
|
14
|
+
import { store as noticesStore } from "@wordpress/notices";
|
|
15
|
+
import { speak } from "@wordpress/a11y";
|
|
16
|
+
import { CATEGORY_SLUG } from "./category-selector";
|
|
17
|
+
function RenamePatternCategoryModal({
|
|
19
18
|
category,
|
|
20
19
|
existingCategories,
|
|
21
20
|
onClose,
|
|
@@ -28,122 +27,128 @@ export default function RenamePatternCategoryModal({
|
|
|
28
27
|
const [name, setName] = useState(decodeEntities(category.name));
|
|
29
28
|
const [isSaving, setIsSaving] = useState(false);
|
|
30
29
|
const [validationMessage, setValidationMessage] = useState(false);
|
|
31
|
-
const validationMessageId = validationMessage ? `patterns-rename-pattern-category-modal__validation-message-${id}` :
|
|
32
|
-
const {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
} = useDispatch(coreStore);
|
|
36
|
-
const {
|
|
37
|
-
createErrorNotice,
|
|
38
|
-
createSuccessNotice
|
|
39
|
-
} = useDispatch(noticesStore);
|
|
40
|
-
const onChange = newName => {
|
|
30
|
+
const validationMessageId = validationMessage ? `patterns-rename-pattern-category-modal__validation-message-${id}` : void 0;
|
|
31
|
+
const { saveEntityRecord, invalidateResolution } = useDispatch(coreStore);
|
|
32
|
+
const { createErrorNotice, createSuccessNotice } = useDispatch(noticesStore);
|
|
33
|
+
const onChange = (newName) => {
|
|
41
34
|
if (validationMessage) {
|
|
42
|
-
setValidationMessage(
|
|
35
|
+
setValidationMessage(void 0);
|
|
43
36
|
}
|
|
44
37
|
setName(newName);
|
|
45
38
|
};
|
|
46
|
-
const onSave = async event => {
|
|
39
|
+
const onSave = async (event) => {
|
|
47
40
|
event.preventDefault();
|
|
48
41
|
if (isSaving) {
|
|
49
42
|
return;
|
|
50
43
|
}
|
|
51
44
|
if (!name || name === category.name) {
|
|
52
|
-
const message = __(
|
|
53
|
-
speak(message,
|
|
45
|
+
const message = __("Please enter a new name for this category.");
|
|
46
|
+
speak(message, "assertive");
|
|
54
47
|
setValidationMessage(message);
|
|
55
48
|
textControlRef.current?.focus();
|
|
56
49
|
return;
|
|
57
50
|
}
|
|
58
|
-
|
|
59
|
-
// Check existing categories to avoid creating duplicates.
|
|
60
|
-
if (existingCategories.patternCategories.find(existingCategory => {
|
|
61
|
-
// Compare the id so that the we don't disallow the user changing the case of their current category
|
|
62
|
-
// (i.e. renaming 'test' to 'Test').
|
|
51
|
+
if (existingCategories.patternCategories.find((existingCategory) => {
|
|
63
52
|
return existingCategory.id !== category.id && existingCategory.label.toLowerCase() === name.toLowerCase();
|
|
64
53
|
})) {
|
|
65
|
-
const message = __(
|
|
66
|
-
|
|
54
|
+
const message = __(
|
|
55
|
+
"This category already exists. Please use a different name."
|
|
56
|
+
);
|
|
57
|
+
speak(message, "assertive");
|
|
67
58
|
setValidationMessage(message);
|
|
68
59
|
textControlRef.current?.focus();
|
|
69
60
|
return;
|
|
70
61
|
}
|
|
71
62
|
try {
|
|
72
63
|
setIsSaving(true);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
invalidateResolution('getUserPatternCategories');
|
|
64
|
+
const savedRecord = await saveEntityRecord(
|
|
65
|
+
"taxonomy",
|
|
66
|
+
CATEGORY_SLUG,
|
|
67
|
+
{
|
|
68
|
+
id: category.id,
|
|
69
|
+
slug: category.slug,
|
|
70
|
+
name
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
invalidateResolution("getUserPatternCategories");
|
|
84
74
|
onSuccess?.(savedRecord);
|
|
85
75
|
onClose();
|
|
86
|
-
createSuccessNotice(__(
|
|
87
|
-
type:
|
|
88
|
-
id:
|
|
76
|
+
createSuccessNotice(__("Pattern category renamed."), {
|
|
77
|
+
type: "snackbar",
|
|
78
|
+
id: "pattern-category-update"
|
|
89
79
|
});
|
|
90
80
|
} catch (error) {
|
|
91
81
|
onError?.();
|
|
92
82
|
createErrorNotice(error.message, {
|
|
93
|
-
type:
|
|
94
|
-
id:
|
|
83
|
+
type: "snackbar",
|
|
84
|
+
id: "pattern-category-update"
|
|
95
85
|
});
|
|
96
86
|
} finally {
|
|
97
87
|
setIsSaving(false);
|
|
98
|
-
setName(
|
|
88
|
+
setName("");
|
|
99
89
|
}
|
|
100
90
|
};
|
|
101
91
|
const onRequestClose = () => {
|
|
102
92
|
onClose();
|
|
103
|
-
setName(
|
|
93
|
+
setName("");
|
|
104
94
|
};
|
|
105
|
-
return
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
children:
|
|
112
|
-
spacing: "
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
95
|
+
return /* @__PURE__ */ jsx(
|
|
96
|
+
Modal,
|
|
97
|
+
{
|
|
98
|
+
title: __("Rename"),
|
|
99
|
+
onRequestClose,
|
|
100
|
+
...props,
|
|
101
|
+
children: /* @__PURE__ */ jsx("form", { onSubmit: onSave, children: /* @__PURE__ */ jsxs(VStack, { spacing: "5", children: [
|
|
102
|
+
/* @__PURE__ */ jsxs(VStack, { spacing: "2", children: [
|
|
103
|
+
/* @__PURE__ */ jsx(
|
|
104
|
+
TextControl,
|
|
105
|
+
{
|
|
106
|
+
ref: textControlRef,
|
|
107
|
+
__nextHasNoMarginBottom: true,
|
|
108
|
+
__next40pxDefaultSize: true,
|
|
109
|
+
label: __("Name"),
|
|
110
|
+
value: name,
|
|
111
|
+
onChange,
|
|
112
|
+
"aria-describedby": validationMessageId,
|
|
113
|
+
required: true
|
|
114
|
+
}
|
|
115
|
+
),
|
|
116
|
+
validationMessage && /* @__PURE__ */ jsx(
|
|
117
|
+
"span",
|
|
118
|
+
{
|
|
119
|
+
className: "patterns-rename-pattern-category-modal__validation-message",
|
|
120
|
+
id: validationMessageId,
|
|
121
|
+
children: validationMessage
|
|
122
|
+
}
|
|
123
|
+
)
|
|
124
|
+
] }),
|
|
125
|
+
/* @__PURE__ */ jsxs(HStack, { justify: "right", children: [
|
|
126
|
+
/* @__PURE__ */ jsx(
|
|
127
|
+
Button,
|
|
128
|
+
{
|
|
129
|
+
__next40pxDefaultSize: true,
|
|
130
|
+
variant: "tertiary",
|
|
131
|
+
onClick: onRequestClose,
|
|
132
|
+
children: __("Cancel")
|
|
133
|
+
}
|
|
134
|
+
),
|
|
135
|
+
/* @__PURE__ */ jsx(
|
|
136
|
+
Button,
|
|
137
|
+
{
|
|
138
|
+
__next40pxDefaultSize: true,
|
|
139
|
+
variant: "primary",
|
|
140
|
+
type: "submit",
|
|
141
|
+
"aria-disabled": !name || name === category.name || isSaving,
|
|
142
|
+
isBusy: isSaving,
|
|
143
|
+
children: __("Save")
|
|
144
|
+
}
|
|
145
|
+
)
|
|
146
|
+
] })
|
|
147
|
+
] }) })
|
|
148
|
+
}
|
|
149
|
+
);
|
|
148
150
|
}
|
|
149
|
-
|
|
151
|
+
export {
|
|
152
|
+
RenamePatternCategoryModal as default
|
|
153
|
+
};
|
|
154
|
+
//# sourceMappingURL=rename-pattern-category-modal.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{"version":3,"names":["Modal","Button","TextControl","__experimentalHStack","HStack","__experimentalVStack","VStack","store","coreStore","useDispatch","useId","useRef","useState","decodeEntities","__","noticesStore","speak","CATEGORY_SLUG","jsx","_jsx","jsxs","_jsxs","RenamePatternCategoryModal","category","existingCategories","onClose","onError","onSuccess","props","id","textControlRef","name","setName","isSaving","setIsSaving","validationMessage","setValidationMessage","validationMessageId","undefined","saveEntityRecord","invalidateResolution","createErrorNotice","createSuccessNotice","onChange","newName","onSave","event","preventDefault","message","current","focus","patternCategories","find","existingCategory","label","toLowerCase","savedRecord","slug","type","error","onRequestClose","title","children","onSubmit","spacing","ref","__nextHasNoMarginBottom","__next40pxDefaultSize","value","required","className","justify","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\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,mBAAqB;YACxCgC,QAAQ;UAAA,CACR,CAAC,EACAlC,iBAAiB,iBAClBhB,IAAA;YACCmD,SAAS,EAAC,4DAA4D;YACtEzC,EAAE,EAAGQ,mBAAqB;YAAAyB,QAAA,EAExB3B;UAAiB,CACd,CACN;QAAA,CACM,CAAC,eACTd,KAAA,CAACjB,MAAM;UAACmE,OAAO,EAAC,OAAO;UAAAT,QAAA,gBACtB3C,IAAA,CAAClB,MAAM;YACNkE,qBAAqB;YACrBK,OAAO,EAAC,UAAU;YAClBC,OAAO,EAAGb,cAAgB;YAAAE,QAAA,EAExBhD,EAAE,CAAE,QAAS;UAAC,CACT,CAAC,eACTK,IAAA,CAAClB,MAAM;YACNkE,qBAAqB;YACrBK,OAAO,EAAC,SAAS;YACjBd,IAAI,EAAC,QAAQ;YACb,iBACC,CAAE3B,IAAI,IAAIA,IAAI,KAAKR,QAAQ,CAACQ,IAAI,IAAIE,QACpC;YACDyC,MAAM,EAAGzC,QAAU;YAAA6B,QAAA,EAEjBhD,EAAE,CAAE,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": "AAwIK,SACC,KADD;AArIL;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA,wBAAwB;AAAA,EACxB,wBAAwB;AAAA,OAClB;AACP,SAAS,SAAS,iBAAiB;AACnC,SAAS,mBAAmB;AAC5B,SAAS,OAAO,QAAQ,gBAAgB;AACxC,SAAS,sBAAsB;AAC/B,SAAS,UAAU;AACnB,SAAS,SAAS,oBAAoB;AACtC,SAAS,aAAa;AAKtB,SAAS,qBAAqB;AAEf,SAAR,2BAA6C;AAAA,EACnD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACJ,GAAI;AACH,QAAM,KAAK,MAAM;AACjB,QA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