@wordpress/patterns 1.18.0 → 2.0.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 +8 -0
- package/build/api/index.js +17 -0
- package/build/api/index.js.map +1 -1
- package/build/components/allow-overrides-modal.js +72 -58
- package/build/components/allow-overrides-modal.js.map +1 -1
- package/build/components/category-selector.js +2 -2
- package/build/components/category-selector.js.map +1 -1
- package/build/components/create-pattern-modal.js +56 -48
- package/build/components/create-pattern-modal.js.map +1 -1
- package/build/components/duplicate-pattern-modal.js +2 -2
- package/build/components/duplicate-pattern-modal.js.map +1 -1
- package/build/components/index.js +15 -11
- package/build/components/index.js.map +1 -1
- package/build/components/overrides-panel.js +7 -6
- package/build/components/overrides-panel.js.map +1 -1
- package/build/components/pattern-convert-button.js +22 -20
- package/build/components/pattern-convert-button.js.map +1 -1
- package/build/components/pattern-overrides-controls.js +49 -54
- package/build/components/pattern-overrides-controls.js.map +1 -1
- package/build/components/patterns-manage-button.js +11 -7
- package/build/components/patterns-manage-button.js.map +1 -1
- package/build/components/rename-pattern-category-modal.js +42 -34
- package/build/components/rename-pattern-category-modal.js.map +1 -1
- package/build/components/rename-pattern-modal.js +31 -25
- package/build/components/rename-pattern-modal.js.map +1 -1
- package/build/components/reset-overrides-control.js +55 -42
- package/build/components/reset-overrides-control.js.map +1 -1
- package/build/private-apis.js +1 -0
- package/build/private-apis.js.map +1 -1
- package/build/store/actions.js +15 -1
- package/build/store/actions.js.map +1 -1
- package/build-module/api/index.js +16 -0
- package/build-module/api/index.js.map +1 -1
- package/build-module/components/allow-overrides-modal.js +73 -58
- package/build-module/components/allow-overrides-modal.js.map +1 -1
- package/build-module/components/category-selector.js +2 -2
- package/build-module/components/category-selector.js.map +1 -1
- package/build-module/components/create-pattern-modal.js +59 -50
- package/build-module/components/create-pattern-modal.js.map +1 -1
- package/build-module/components/duplicate-pattern-modal.js +2 -2
- package/build-module/components/duplicate-pattern-modal.js.map +1 -1
- package/build-module/components/index.js +17 -11
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/overrides-panel.js +7 -6
- package/build-module/components/overrides-panel.js.map +1 -1
- package/build-module/components/pattern-convert-button.js +23 -18
- package/build-module/components/pattern-convert-button.js.map +1 -1
- package/build-module/components/pattern-overrides-controls.js +52 -55
- package/build-module/components/pattern-overrides-controls.js.map +1 -1
- package/build-module/components/patterns-manage-button.js +13 -7
- package/build-module/components/patterns-manage-button.js.map +1 -1
- package/build-module/components/rename-pattern-category-modal.js +43 -34
- package/build-module/components/rename-pattern-category-modal.js.map +1 -1
- package/build-module/components/rename-pattern-modal.js +32 -25
- package/build-module/components/rename-pattern-modal.js.map +1 -1
- package/build-module/components/reset-overrides-control.js +56 -43
- package/build-module/components/reset-overrides-control.js.map +1 -1
- package/build-module/private-apis.js +2 -1
- package/build-module/private-apis.js.map +1 -1
- package/build-module/store/actions.js +16 -2
- package/build-module/store/actions.js.map +1 -1
- package/package.json +18 -17
- package/src/api/index.js +16 -0
- package/src/components/create-pattern-modal.js +16 -5
- package/src/components/pattern-overrides-controls.js +19 -44
- package/src/components/patterns-manage-button.js +1 -1
- package/src/components/reset-overrides-control.js +54 -50
- package/src/private-apis.js +2 -1
- package/src/store/actions.js +25 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["privateApis","blockEditorPrivateApis","store","blockEditorStore","PanelBody","useSelect","useMemo","__","isOverridableBlock","unlock","BlockQuickNavigation","OverridesPanel","allClientIds","select","getClientIdsWithDescendants","getBlock","clientIdsWithOverrides","filter","clientId","block","length","
|
|
1
|
+
{"version":3,"names":["privateApis","blockEditorPrivateApis","store","blockEditorStore","PanelBody","useSelect","useMemo","__","isOverridableBlock","unlock","jsx","_jsx","BlockQuickNavigation","OverridesPanel","allClientIds","select","getClientIdsWithDescendants","getBlock","clientIdsWithOverrides","filter","clientId","block","length","title","children","clientIds"],"sources":["@wordpress/patterns/src/components/overrides-panel.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tprivateApis as blockEditorPrivateApis,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { PanelBody } from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\nimport { useMemo } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { isOverridableBlock } from '../api';\nimport { unlock } from '../lock-unlock';\n\nconst { BlockQuickNavigation } = unlock( blockEditorPrivateApis );\n\nexport default function OverridesPanel() {\n\tconst allClientIds = useSelect(\n\t\t( select ) => select( blockEditorStore ).getClientIdsWithDescendants(),\n\t\t[]\n\t);\n\tconst { getBlock } = useSelect( blockEditorStore );\n\tconst clientIdsWithOverrides = useMemo(\n\t\t() =>\n\t\t\tallClientIds.filter( ( clientId ) => {\n\t\t\t\tconst block = getBlock( clientId );\n\t\t\t\treturn isOverridableBlock( block );\n\t\t\t} ),\n\t\t[ allClientIds, getBlock ]\n\t);\n\n\tif ( ! clientIdsWithOverrides?.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<PanelBody title={ __( 'Overrides' ) }>\n\t\t\t<BlockQuickNavigation clientIds={ clientIdsWithOverrides } />\n\t\t</PanelBody>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SACCA,WAAW,IAAIC,sBAAsB,EACrCC,KAAK,IAAIC,gBAAgB,QACnB,yBAAyB;AAChC,SAASC,SAAS,QAAQ,uBAAuB;AACjD,SAASC,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,OAAO,QAAQ,oBAAoB;AAC5C,SAASC,EAAE,QAAQ,iBAAiB;;AAEpC;AACA;AACA;AACA,SAASC,kBAAkB,QAAQ,QAAQ;AAC3C,SAASC,MAAM,QAAQ,gBAAgB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAExC,MAAM;EAAEC;AAAqB,CAAC,GAAGH,MAAM,CAAER,sBAAuB,CAAC;AAEjE,eAAe,SAASY,cAAcA,CAAA,EAAG;EACxC,MAAMC,YAAY,GAAGT,SAAS,CAC3BU,MAAM,IAAMA,MAAM,CAAEZ,gBAAiB,CAAC,CAACa,2BAA2B,CAAC,CAAC,EACtE,EACD,CAAC;EACD,MAAM;IAAEC;EAAS,CAAC,GAAGZ,SAAS,CAAEF,gBAAiB,CAAC;EAClD,MAAMe,sBAAsB,GAAGZ,OAAO,CACrC,MACCQ,YAAY,CAACK,MAAM,CAAIC,QAAQ,IAAM;IACpC,MAAMC,KAAK,GAAGJ,QAAQ,CAAEG,QAAS,CAAC;IAClC,OAAOZ,kBAAkB,CAAEa,KAAM,CAAC;EACnC,CAAE,CAAC,EACJ,CAAEP,YAAY,EAAEG,QAAQ,CACzB,CAAC;EAED,IAAK,CAAEC,sBAAsB,EAAEI,MAAM,EAAG;IACvC,OAAO,IAAI;EACZ;EAEA,oBACCX,IAAA,CAACP,SAAS;IAACmB,KAAK,EAAGhB,EAAE,CAAE,WAAY,CAAG;IAAAiB,QAAA,eACrCb,IAAA,CAACC,oBAAoB;MAACa,SAAS,EAAGP;IAAwB,CAAE;EAAC,CACnD,CAAC;AAEd","ignoreList":[]}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { createElement, Fragment } from "react";
|
|
2
1
|
/**
|
|
3
2
|
* WordPress dependencies
|
|
4
3
|
*/
|
|
@@ -28,6 +27,9 @@ import { PATTERN_SYNC_TYPES } from '../constants';
|
|
|
28
27
|
* @param {()=>void} props.closeBlockSettingsMenu Callback to close the block settings menu dropdown.
|
|
29
28
|
* @return {import('react').ComponentType} The menu control or null.
|
|
30
29
|
*/
|
|
30
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
31
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
32
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
31
33
|
export default function PatternConvertButton({
|
|
32
34
|
clientIds,
|
|
33
35
|
rootClientId,
|
|
@@ -101,22 +103,25 @@ export default function PatternConvertButton({
|
|
|
101
103
|
});
|
|
102
104
|
setIsModalOpen(false);
|
|
103
105
|
};
|
|
104
|
-
return
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
106
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
107
|
+
children: [/*#__PURE__*/_jsx(MenuItem, {
|
|
108
|
+
icon: symbol,
|
|
109
|
+
onClick: () => setIsModalOpen(true),
|
|
110
|
+
"aria-expanded": isModalOpen,
|
|
111
|
+
"aria-haspopup": "dialog",
|
|
112
|
+
children: __('Create pattern')
|
|
113
|
+
}), isModalOpen && /*#__PURE__*/_jsx(CreatePatternModal, {
|
|
114
|
+
content: getContent,
|
|
115
|
+
onSuccess: pattern => {
|
|
116
|
+
handleSuccess(pattern);
|
|
117
|
+
},
|
|
118
|
+
onError: () => {
|
|
119
|
+
setIsModalOpen(false);
|
|
120
|
+
},
|
|
121
|
+
onClose: () => {
|
|
122
|
+
setIsModalOpen(false);
|
|
123
|
+
}
|
|
124
|
+
})]
|
|
125
|
+
});
|
|
121
126
|
}
|
|
122
127
|
//# sourceMappingURL=pattern-convert-button.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["hasBlockSupport","isReusableBlock","createBlock","serialize","store","blockEditorStore","useState","useCallback","MenuItem","symbol","useSelect","useDispatch","coreStore","__","sprintf","noticesStore","patternsStore","CreatePatternModal","unlock","PATTERN_SYNC_TYPES","PatternConvertButton","clientIds","rootClientId","closeBlockSettingsMenu","createSuccessNotice","replaceBlocks","setEditingPattern","isModalOpen","setIsModalOpen","canConvert","select","_getBlocksByClientId","canUser","getBlocksByClientId","canInsertBlockType","getBlockRootClientId","rootId","length","undefined","blocks","isReusable","getEntityRecord","attributes","ref","_canConvert","every","block","isValid","name","getContent","handleSuccess","pattern","wp_pattern_sync_status","unsynced","newBlock","id","clientId","title","raw","type","
|
|
1
|
+
{"version":3,"names":["hasBlockSupport","isReusableBlock","createBlock","serialize","store","blockEditorStore","useState","useCallback","MenuItem","symbol","useSelect","useDispatch","coreStore","__","sprintf","noticesStore","patternsStore","CreatePatternModal","unlock","PATTERN_SYNC_TYPES","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","PatternConvertButton","clientIds","rootClientId","closeBlockSettingsMenu","createSuccessNotice","replaceBlocks","setEditingPattern","isModalOpen","setIsModalOpen","canConvert","select","_getBlocksByClientId","canUser","getBlocksByClientId","canInsertBlockType","getBlockRootClientId","rootId","length","undefined","blocks","isReusable","getEntityRecord","attributes","ref","_canConvert","every","block","isValid","name","getContent","handleSuccess","pattern","wp_pattern_sync_status","unsynced","newBlock","id","clientId","title","raw","type","children","icon","onClick","content","onSuccess","onError","onClose"],"sources":["@wordpress/patterns/src/components/pattern-convert-button.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\thasBlockSupport,\n\tisReusableBlock,\n\tcreateBlock,\n\tserialize,\n} from '@wordpress/blocks';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { useState, useCallback } from '@wordpress/element';\nimport { MenuItem } from '@wordpress/components';\nimport { symbol } from '@wordpress/icons';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n/**\n * Internal dependencies\n */\nimport { store as patternsStore } from '../store';\nimport CreatePatternModal from './create-pattern-modal';\nimport { unlock } from '../lock-unlock';\nimport { PATTERN_SYNC_TYPES } from '../constants';\n\n/**\n * Menu control to convert block(s) to a pattern block.\n *\n * @param {Object} props Component props.\n * @param {string[]} props.clientIds Client ids of selected blocks.\n * @param {string} props.rootClientId ID of the currently selected top-level block.\n * @param {()=>void} props.closeBlockSettingsMenu Callback to close the block settings menu dropdown.\n * @return {import('react').ComponentType} The menu control or null.\n */\nexport default function PatternConvertButton( {\n\tclientIds,\n\trootClientId,\n\tcloseBlockSettingsMenu,\n} ) {\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\tconst { replaceBlocks } = useDispatch( blockEditorStore );\n\t// Ignore reason: false positive of the lint rule.\n\t// eslint-disable-next-line @wordpress/no-unused-vars-before-return\n\tconst { setEditingPattern } = unlock( useDispatch( patternsStore ) );\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\tconst canConvert = useSelect(\n\t\t( select ) => {\n\t\t\tconst { canUser } = select( coreStore );\n\t\t\tconst {\n\t\t\t\tgetBlocksByClientId,\n\t\t\t\tcanInsertBlockType,\n\t\t\t\tgetBlockRootClientId,\n\t\t\t} = select( blockEditorStore );\n\n\t\t\tconst rootId =\n\t\t\t\trootClientId ||\n\t\t\t\t( clientIds.length > 0\n\t\t\t\t\t? getBlockRootClientId( clientIds[ 0 ] )\n\t\t\t\t\t: undefined );\n\n\t\t\tconst blocks = getBlocksByClientId( clientIds ) ?? [];\n\n\t\t\tconst isReusable =\n\t\t\t\tblocks.length === 1 &&\n\t\t\t\tblocks[ 0 ] &&\n\t\t\t\tisReusableBlock( blocks[ 0 ] ) &&\n\t\t\t\t!! select( coreStore ).getEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'wp_block',\n\t\t\t\t\tblocks[ 0 ].attributes.ref\n\t\t\t\t);\n\n\t\t\tconst _canConvert =\n\t\t\t\t// Hide when this is already a synced pattern.\n\t\t\t\t! isReusable &&\n\t\t\t\t// Hide when patterns are disabled.\n\t\t\t\tcanInsertBlockType( 'core/block', rootId ) &&\n\t\t\t\tblocks.every(\n\t\t\t\t\t( block ) =>\n\t\t\t\t\t\t// Guard against the case where a regular block has *just* been converted.\n\t\t\t\t\t\t!! block &&\n\t\t\t\t\t\t// Hide on invalid blocks.\n\t\t\t\t\t\tblock.isValid &&\n\t\t\t\t\t\t// Hide when block doesn't support being made into a pattern.\n\t\t\t\t\t\thasBlockSupport( block.name, 'reusable', true )\n\t\t\t\t) &&\n\t\t\t\t// Hide when current doesn't have permission to do that.\n\t\t\t\t!! canUser( 'create', 'blocks' );\n\n\t\t\treturn _canConvert;\n\t\t},\n\t\t[ clientIds, rootClientId ]\n\t);\n\tconst { getBlocksByClientId } = useSelect( blockEditorStore );\n\tconst getContent = useCallback(\n\t\t() => serialize( getBlocksByClientId( clientIds ) ),\n\t\t[ getBlocksByClientId, clientIds ]\n\t);\n\n\tif ( ! canConvert ) {\n\t\treturn null;\n\t}\n\n\tconst handleSuccess = ( { pattern } ) => {\n\t\tif ( pattern.wp_pattern_sync_status !== PATTERN_SYNC_TYPES.unsynced ) {\n\t\t\tconst newBlock = createBlock( 'core/block', {\n\t\t\t\tref: pattern.id,\n\t\t\t} );\n\n\t\t\treplaceBlocks( clientIds, newBlock );\n\t\t\tsetEditingPattern( newBlock.clientId, true );\n\t\t\tcloseBlockSettingsMenu();\n\t\t}\n\n\t\tcreateSuccessNotice(\n\t\t\tpattern.wp_pattern_sync_status === PATTERN_SYNC_TYPES.unsynced\n\t\t\t\t? sprintf(\n\t\t\t\t\t\t// translators: %s: the name the user has given to the pattern.\n\t\t\t\t\t\t__( 'Unsynced pattern created: %s' ),\n\t\t\t\t\t\tpattern.title.raw\n\t\t\t\t )\n\t\t\t\t: sprintf(\n\t\t\t\t\t\t// translators: %s: the name the user has given to the pattern.\n\t\t\t\t\t\t__( 'Synced pattern created: %s' ),\n\t\t\t\t\t\tpattern.title.raw\n\t\t\t\t ),\n\t\t\t{\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'convert-to-pattern-success',\n\t\t\t}\n\t\t);\n\t\tsetIsModalOpen( false );\n\t};\n\treturn (\n\t\t<>\n\t\t\t<MenuItem\n\t\t\t\ticon={ symbol }\n\t\t\t\tonClick={ () => setIsModalOpen( true ) }\n\t\t\t\taria-expanded={ isModalOpen }\n\t\t\t\taria-haspopup=\"dialog\"\n\t\t\t>\n\t\t\t\t{ __( 'Create pattern' ) }\n\t\t\t</MenuItem>\n\t\t\t{ isModalOpen && (\n\t\t\t\t<CreatePatternModal\n\t\t\t\t\tcontent={ getContent }\n\t\t\t\t\tonSuccess={ ( pattern ) => {\n\t\t\t\t\t\thandleSuccess( pattern );\n\t\t\t\t\t} }\n\t\t\t\t\tonError={ () => {\n\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t} }\n\t\t\t\t\tonClose={ () => {\n\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SACCA,eAAe,EACfC,eAAe,EACfC,WAAW,EACXC,SAAS,QACH,mBAAmB;AAC1B,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,yBAAyB;AACnE,SAASC,QAAQ,EAAEC,WAAW,QAAQ,oBAAoB;AAC1D,SAASC,QAAQ,QAAQ,uBAAuB;AAChD,SAASC,MAAM,QAAQ,kBAAkB;AACzC,SAASC,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACxD,SAASP,KAAK,IAAIQ,SAAS,QAAQ,sBAAsB;AACzD,SAASC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AAC7C,SAASV,KAAK,IAAIW,YAAY,QAAQ,oBAAoB;AAC1D;AACA;AACA;AACA,SAASX,KAAK,IAAIY,aAAa,QAAQ,UAAU;AACjD,OAAOC,kBAAkB,MAAM,wBAAwB;AACvD,SAASC,MAAM,QAAQ,gBAAgB;AACvC,SAASC,kBAAkB,QAAQ,cAAc;;AAEjD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AARA,SAAAC,GAAA,IAAAC,IAAA;AAAA,SAAAC,QAAA,IAAAC,SAAA;AAAA,SAAAC,IAAA,IAAAC,KAAA;AASA,eAAe,SAASC,oBAAoBA,CAAE;EAC7CC,SAAS;EACTC,YAAY;EACZC;AACD,CAAC,EAAG;EACH,MAAM;IAAEC;E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ACD3B,cAAc,CAAE,KAAM,CAAC;EACxB,CAAC;EACD,oBACCT,KAAA,CAAAF,SAAA;IAAA2C,QAAA,gBACC7C,IAAA,CAACb,QAAQ;MACR2D,IAAI,EAAG1D,MAAQ;MACf2D,OAAO,EAAGA,CAAA,KAAMlC,cAAc,CAAE,IAAK,CAAG;MACxC,iBAAgBD,WAAa;MAC7B,iBAAc,QAAQ;MAAAiC,QAAA,EAEpBrD,EAAE,CAAE,gBAAiB;IAAC,CACf,CAAC,EACToB,WAAW,iBACZZ,IAAA,CAACJ,kBAAkB;MAClBoD,OAAO,EAAGd,UAAY;MACtBe,SAAS,EAAKb,OAAO,IAAM;QAC1BD,aAAa,CAAEC,OAAQ,CAAC;MACzB,CAAG;MACHc,OAAO,EAAGA,CAAA,KAAM;QACfrC,cAAc,CAAE,KAAM,CAAC;MACxB,CAAG;MACHsC,OAAO,EAAGA,CAAA,KAAM;QACftC,cAAc,CAAE,KAAM,CAAC;MACxB;IAAG,CACH,CACD;EAAA,CACA,CAAC;AAEL","ignoreList":[]}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { createElement, Fragment } from "react";
|
|
2
1
|
/**
|
|
3
2
|
* WordPress dependencies
|
|
4
3
|
*/
|
|
@@ -10,48 +9,43 @@ import { __ } from '@wordpress/i18n';
|
|
|
10
9
|
/**
|
|
11
10
|
* Internal dependencies
|
|
12
11
|
*/
|
|
13
|
-
import {
|
|
12
|
+
import { PATTERN_OVERRIDES_BINDING_SOURCE } from '../constants';
|
|
14
13
|
import { AllowOverridesModal, DisallowOverridesModal } from './allow-overrides-modal';
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
16
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
|
+
function removeBindings(bindings) {
|
|
18
|
+
let updatedBindings = {
|
|
19
|
+
...bindings
|
|
20
|
+
};
|
|
21
|
+
delete updatedBindings.__default;
|
|
23
22
|
if (!Object.keys(updatedBindings).length) {
|
|
24
23
|
updatedBindings = undefined;
|
|
25
24
|
}
|
|
26
25
|
return updatedBindings;
|
|
27
26
|
}
|
|
28
|
-
function addBindings(bindings
|
|
29
|
-
|
|
30
|
-
...bindings
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (!bindings?.[attributeName]) {
|
|
34
|
-
updatedBindings[attributeName] = {
|
|
35
|
-
source: PATTERN_OVERRIDES_BINDING_SOURCE
|
|
36
|
-
};
|
|
27
|
+
function addBindings(bindings) {
|
|
28
|
+
return {
|
|
29
|
+
...bindings,
|
|
30
|
+
__default: {
|
|
31
|
+
source: PATTERN_OVERRIDES_BINDING_SOURCE
|
|
37
32
|
}
|
|
38
|
-
}
|
|
39
|
-
return updatedBindings;
|
|
33
|
+
};
|
|
40
34
|
}
|
|
41
35
|
function PatternOverridesControls({
|
|
42
36
|
attributes,
|
|
43
|
-
name,
|
|
44
37
|
setAttributes
|
|
45
38
|
}) {
|
|
46
39
|
const controlId = useId();
|
|
47
40
|
const [showAllowOverridesModal, setShowAllowOverridesModal] = useState(false);
|
|
48
41
|
const [showDisallowOverridesModal, setShowDisallowOverridesModal] = useState(false);
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
const
|
|
42
|
+
const hasName = !!attributes.metadata?.name;
|
|
43
|
+
const defaultBindings = attributes.metadata?.bindings?.__default;
|
|
44
|
+
const allowOverrides = hasName && defaultBindings?.source === PATTERN_OVERRIDES_BINDING_SOURCE;
|
|
45
|
+
const isConnectedToOtherSources = defaultBindings?.source && defaultBindings.source !== PATTERN_OVERRIDES_BINDING_SOURCE;
|
|
52
46
|
function updateBindings(isChecked, customName) {
|
|
53
47
|
const prevBindings = attributes?.metadata?.bindings;
|
|
54
|
-
const updatedBindings = isChecked ? addBindings(prevBindings
|
|
48
|
+
const updatedBindings = isChecked ? addBindings(prevBindings) : removeBindings(prevBindings);
|
|
55
49
|
const updatedMetadata = {
|
|
56
50
|
...attributes.metadata,
|
|
57
51
|
bindings: updatedBindings
|
|
@@ -68,36 +62,39 @@ function PatternOverridesControls({
|
|
|
68
62
|
if (isConnectedToOtherSources) {
|
|
69
63
|
return null;
|
|
70
64
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
65
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
66
|
+
children: [/*#__PURE__*/_jsx(InspectorControls, {
|
|
67
|
+
group: "advanced",
|
|
68
|
+
children: /*#__PURE__*/_jsx(BaseControl, {
|
|
69
|
+
id: controlId,
|
|
70
|
+
label: __('Overrides'),
|
|
71
|
+
help: __('Allow changes to this block throughout instances of this pattern.'),
|
|
72
|
+
children: /*#__PURE__*/_jsx(Button, {
|
|
73
|
+
__next40pxDefaultSize: true,
|
|
74
|
+
className: "pattern-overrides-control__allow-overrides-button",
|
|
75
|
+
variant: "secondary",
|
|
76
|
+
"aria-haspopup": "dialog",
|
|
77
|
+
onClick: () => {
|
|
78
|
+
if (allowOverrides) {
|
|
79
|
+
setShowDisallowOverridesModal(true);
|
|
80
|
+
} else {
|
|
81
|
+
setShowAllowOverridesModal(true);
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
children: allowOverrides ? __('Disable overrides') : __('Enable overrides')
|
|
85
|
+
})
|
|
86
|
+
})
|
|
87
|
+
}), showAllowOverridesModal && /*#__PURE__*/_jsx(AllowOverridesModal, {
|
|
88
|
+
initialName: attributes.metadata?.name,
|
|
89
|
+
onClose: () => setShowAllowOverridesModal(false),
|
|
90
|
+
onSave: newName => {
|
|
91
|
+
updateBindings(true, newName);
|
|
89
92
|
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
updateBindings(true, newName);
|
|
96
|
-
}
|
|
97
|
-
}), showDisallowOverridesModal && createElement(DisallowOverridesModal, {
|
|
98
|
-
onClose: () => setShowDisallowOverridesModal(false),
|
|
99
|
-
onSave: () => updateBindings(false)
|
|
100
|
-
}));
|
|
93
|
+
}), showDisallowOverridesModal && /*#__PURE__*/_jsx(DisallowOverridesModal, {
|
|
94
|
+
onClose: () => setShowDisallowOverridesModal(false),
|
|
95
|
+
onSave: () => updateBindings(false)
|
|
96
|
+
})]
|
|
97
|
+
});
|
|
101
98
|
}
|
|
102
99
|
export default PatternOverridesControls;
|
|
103
100
|
//# sourceMappingURL=pattern-overrides-controls.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useState","useId","InspectorControls","BaseControl","Button","__","
|
|
1
|
+
{"version":3,"names":["useState","useId","InspectorControls","BaseControl","Button","__","PATTERN_OVERRIDES_BINDING_SOURCE","AllowOverridesModal","DisallowOverridesModal","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","removeBindings","bindings","updatedBindings","__default","Object","keys","length","undefined","addBindings","source","PatternOverridesControls","attributes","setAttributes","controlId","showAllowOverridesModal","setShowAllowOverridesModal","showDisallowOverridesModal","setShowDisallowOverridesModal","hasName","metadata","name","defaultBindings","allowOverrides","isConnectedToOtherSources","updateBindings","isChecked","customName","prevBindings","updatedMetadata","children","group","id","label","help","__next40pxDefaultSize","className","variant","onClick","initialName","onClose","onSave","newName"],"sources":["@wordpress/patterns/src/components/pattern-overrides-controls.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useId } from '@wordpress/element';\nimport { InspectorControls } from '@wordpress/block-editor';\nimport { BaseControl, Button } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { PATTERN_OVERRIDES_BINDING_SOURCE } from '../constants';\nimport {\n\tAllowOverridesModal,\n\tDisallowOverridesModal,\n} from './allow-overrides-modal';\n\nfunction removeBindings( bindings ) {\n\tlet updatedBindings = { ...bindings };\n\tdelete updatedBindings.__default;\n\tif ( ! Object.keys( updatedBindings ).length ) {\n\t\tupdatedBindings = undefined;\n\t}\n\treturn updatedBindings;\n}\n\nfunction addBindings( bindings ) {\n\treturn {\n\t\t...bindings,\n\t\t__default: { source: PATTERN_OVERRIDES_BINDING_SOURCE },\n\t};\n}\n\nfunction PatternOverridesControls( { attributes, setAttributes } ) {\n\tconst controlId = useId();\n\tconst [ showAllowOverridesModal, setShowAllowOverridesModal ] =\n\t\tuseState( false );\n\tconst [ showDisallowOverridesModal, setShowDisallowOverridesModal ] =\n\t\tuseState( false );\n\n\tconst hasName = !! attributes.metadata?.name;\n\tconst defaultBindings = attributes.metadata?.bindings?.__default;\n\tconst allowOverrides =\n\t\thasName && defaultBindings?.source === PATTERN_OVERRIDES_BINDING_SOURCE;\n\tconst isConnectedToOtherSources =\n\t\tdefaultBindings?.source &&\n\t\tdefaultBindings.source !== PATTERN_OVERRIDES_BINDING_SOURCE;\n\n\tfunction updateBindings( isChecked, customName ) {\n\t\tconst prevBindings = attributes?.metadata?.bindings;\n\t\tconst updatedBindings = isChecked\n\t\t\t? addBindings( prevBindings )\n\t\t\t: removeBindings( prevBindings );\n\n\t\tconst updatedMetadata = {\n\t\t\t...attributes.metadata,\n\t\t\tbindings: updatedBindings,\n\t\t};\n\n\t\tif ( customName ) {\n\t\t\tupdatedMetadata.name = customName;\n\t\t}\n\n\t\tsetAttributes( {\n\t\t\tmetadata: updatedMetadata,\n\t\t} );\n\t}\n\n\t// Avoid overwriting other (e.g. meta) bindings.\n\tif ( isConnectedToOtherSources ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<InspectorControls group=\"advanced\">\n\t\t\t\t<BaseControl\n\t\t\t\t\tid={ controlId }\n\t\t\t\t\tlabel={ __( 'Overrides' ) }\n\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t'Allow changes to this block throughout instances of this pattern.'\n\t\t\t\t\t) }\n\t\t\t\t>\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tclassName=\"pattern-overrides-control__allow-overrides-button\"\n\t\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\t\taria-haspopup=\"dialog\"\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tif ( allowOverrides ) {\n\t\t\t\t\t\t\t\tsetShowDisallowOverridesModal( true );\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tsetShowAllowOverridesModal( true );\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\t\t{ allowOverrides\n\t\t\t\t\t\t\t? __( 'Disable overrides' )\n\t\t\t\t\t\t\t: __( 'Enable overrides' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</BaseControl>\n\t\t\t</InspectorControls>\n\n\t\t\t{ showAllowOverridesModal && (\n\t\t\t\t<AllowOverridesModal\n\t\t\t\t\tinitialName={ attributes.metadata?.name }\n\t\t\t\t\tonClose={ () => setShowAllowOverridesModal( false ) }\n\t\t\t\t\tonSave={ ( newName ) => {\n\t\t\t\t\t\tupdateBindings( true, newName );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ showDisallowOverridesModal && (\n\t\t\t\t<DisallowOverridesModal\n\t\t\t\t\tonClose={ () => setShowDisallowOverridesModal( false ) }\n\t\t\t\t\tonSave={ () => updateBindings( false ) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport default PatternOverridesControls;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,QAAQ,EAAEC,KAAK,QAAQ,oBAAoB;AACpD,SAASC,iBAAiB,QAAQ,yBAAyB;AAC3D,SAASC,WAAW,EAAEC,MA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,IAAA,CAACH,mBAAmB;MACnB8C,WAAW,EAAG3B,UAAU,CAACQ,QAAQ,EAAEC,IAAM;MACzCmB,OAAO,EAAGA,CAAA,KAAMxB,0BAA0B,CAAE,KAAM,CAAG;MACrDyB,MAAM,EAAKC,OAAO,IAAM;QACvBjB,cAAc,CAAE,IAAI,EAAEiB,OAAQ,CAAC;MAChC;IAAG,CACH,CACD,EACCzB,0BAA0B,iBAC3BrB,IAAA,CAACF,sBAAsB;MACtB8C,OAAO,EAAGA,CAAA,KAAMtB,6BAA6B,CAAE,KAAM,CAAG;MACxDuB,MAAM,EAAGA,CAAA,KAAMhB,cAAc,CAAE,KAAM;IAAG,CACxC,CACD;EAAA,CACA,CAAC;AAEL;AAEA,eAAed,wBAAwB","ignoreList":[]}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { createElement, Fragment } from "react";
|
|
2
1
|
/**
|
|
3
2
|
* WordPress dependencies
|
|
4
3
|
*/
|
|
@@ -15,6 +14,9 @@ import { store as coreStore } from '@wordpress/core-data';
|
|
|
15
14
|
*/
|
|
16
15
|
import { store as patternsStore } from '../store';
|
|
17
16
|
import { unlock } from '../lock-unlock';
|
|
17
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
18
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
19
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
18
20
|
function PatternsManageButton({
|
|
19
21
|
clientId
|
|
20
22
|
}) {
|
|
@@ -39,7 +41,7 @@ function PatternsManageButton({
|
|
|
39
41
|
// The site editor and templates both check whether the user
|
|
40
42
|
// has edit_theme_options capabilities. We can leverage that here
|
|
41
43
|
// and omit the manage patterns link if the user can't access it.
|
|
42
|
-
managePatternsUrl: canUser('
|
|
44
|
+
managePatternsUrl: canUser('create', 'templates') ? addQueryArgs('site-editor.php', {
|
|
43
45
|
path: '/patterns'
|
|
44
46
|
}) : addQueryArgs('edit.php', {
|
|
45
47
|
post_type: 'wp_block'
|
|
@@ -55,11 +57,15 @@ function PatternsManageButton({
|
|
|
55
57
|
if (!isVisible) {
|
|
56
58
|
return null;
|
|
57
59
|
}
|
|
58
|
-
return
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
61
|
+
children: [canRemove && /*#__PURE__*/_jsx(MenuItem, {
|
|
62
|
+
onClick: () => convertSyncedPatternToStatic(clientId),
|
|
63
|
+
children: __('Detach')
|
|
64
|
+
}), /*#__PURE__*/_jsx(MenuItem, {
|
|
65
|
+
href: managePatternsUrl,
|
|
66
|
+
children: __('Manage patterns')
|
|
67
|
+
})]
|
|
68
|
+
});
|
|
63
69
|
}
|
|
64
70
|
export default PatternsManageButton;
|
|
65
71
|
//# sourceMappingURL=patterns-manage-button.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["MenuItem","__","isReusableBlock","useSelect","useDispatch","store","blockEditorStore","addQueryArgs","coreStore","patternsStore","unlock","PatternsManageButton","clientId","canRemove","isVisible","managePatternsUrl","select","getBlock","canRemoveBlock","getBlockCount","canUser","reusableBlock","attributes","ref","innerBlockCount","path","post_type","convertSyncedPatternToStatic","
|
|
1
|
+
{"version":3,"names":["MenuItem","__","isReusableBlock","useSelect","useDispatch","store","blockEditorStore","addQueryArgs","coreStore","patternsStore","unlock","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","PatternsManageButton","clientId","canRemove","isVisible","managePatternsUrl","select","getBlock","canRemoveBlock","getBlockCount","canUser","reusableBlock","attributes","ref","innerBlockCount","path","post_type","convertSyncedPatternToStatic","children","onClick","href"],"sources":["@wordpress/patterns/src/components/patterns-manage-button.js"],"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 { canRemove, isVisible, managePatternsUrl } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlock, canRemoveBlock, getBlockCount } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst { canUser } = select( coreStore );\n\t\t\tconst reusableBlock = getBlock( clientId );\n\n\t\t\treturn {\n\t\t\t\tcanRemove: canRemoveBlock( clientId ),\n\t\t\t\tisVisible:\n\t\t\t\t\t!! reusableBlock &&\n\t\t\t\t\tisReusableBlock( reusableBlock ) &&\n\t\t\t\t\t!! canUser(\n\t\t\t\t\t\t'update',\n\t\t\t\t\t\t'blocks',\n\t\t\t\t\t\treusableBlock.attributes.ref\n\t\t\t\t\t),\n\t\t\t\tinnerBlockCount: getBlockCount( clientId ),\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', 'templates' )\n\t\t\t\t\t? addQueryArgs( 'site-editor.php', {\n\t\t\t\t\t\t\tpath: '/patterns',\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\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{ canRemove && (\n\t\t\t\t<MenuItem\n\t\t\t\t\tonClick={ () => convertSyncedPatternToStatic( clientId ) }\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"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,QAAQ,QAAQ,uBAAuB;AAChD,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,eAAe,QAAQ,mBAAmB;AACnD,SAASC,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACxD,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,yBAAyB;AACnE,SAASC,YAAY,QAAQ,gBAAgB;AAC7C,SAASF,KAAK,IAAIG,SAAS,QAAQ,sBAAsB;;AAEzD;AACA;AACA;AACA,SAASH,KAAK,IAAII,aAAa,QAAQ,UAAU;AACjD,SAASC,MAAM,QAAQ,gBAAgB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAAA,SAAAC,QAAA,IAAAC,SAAA;AAAA,SAAAC,IAAA,IAAAC,KAAA;AAExC,SAASC,oBAAoBA,CAAE;EAAEC;AAAS,CAAC,EAAG;EAC7C,MAAM;IAAEC,SAAS;IAAEC,SAAS;IAAEC;EAAkB,CAAC,GAAGlB,SAAS,CAC1DmB,MAAM,IAAM;IACb,MAAM;MAAEC,QAAQ;MAAEC,cAAc;MAAEC;IAAc,CAAC,GAChDH,MAAM,CAAEhB,gBAAiB,CAAC;IAC3B,MAAM;MAAEoB;IAAQ,CAAC,GAAGJ,MAAM,CAAEd,SAAU,CAAC;IACvC,MAAMmB,aAAa,GAAGJ,QAAQ,CAAEL,QAAS,CAAC;IAE1C,OAAO;MACNC,SAAS,EAAEK,cAAc,CAAEN,QAAS,CAAC;MACrCE,SAAS,EACR,CAAC,CAAEO,aAAa,IAChBzB,eAAe,CAAEyB,aAAc,CAAC,IAChC,CAAC,CAAED,OAAO,CACT,QAAQ,EACR,QAAQ,EACRC,aAAa,CAACC,UAAU,CAACC,GAC1B,CAAC;MACFC,eAAe,EAAEL,aAAa,CAAEP,QAAS,CAAC;MAC1C;MACA;MACA;MACAG,iBAAiB,EAAEK,OAAO,CAAE,QAAQ,EAAE,WAAY,CAAC,GAChDnB,YAAY,CAAE,iBAAiB,EAAE;QACjCwB,IAAI,EAAE;MACN,CAAE,CAAC,GACHxB,YAAY,CAAE,UAAU,EAAE;QAC1ByB,SAAS,EAAE;MACX,CAAE;IACN,CAAC;EACF,CAAC,EACD,CAAEd,QAAQ,CACX,CAAC;;EAED;EACA;EACA,MAAM;IAAEe;EAA6B,CAAC,GAAGvB,MAAM,CAC9CN,WAAW,CAAEK,aAAc,CAC5B,CAAC;EAED,IAAK,CAAEW,SAAS,EAAG;IAClB,OAAO,IAAI;EACZ;EAEA,oBACCJ,KAAA,CAAAF,SAAA;IAAAoB,QAAA,GACGf,SAAS,iBACVP,IAAA,CAACZ,QAAQ;MACRmC,OAAO,EAAGA,CAAA,KAAMF,4BAA4B,CAAEf,QAAS,CAAG;MAAAgB,QAAA,EAExDjC,EAAE,CAAE,QAAS;IAAC,CACP,CACV,eACDW,IAAA,CAACZ,QAAQ;MAACoC,IAAI,EAAGf,iBAAmB;MAAAa,QAAA,EACjCjC,EAAE,CAAE,iBAAkB;IAAC,CAChB,CAAC;EAAA,CACV,CAAC;AAEL;AAEA,eAAegB,oBAAoB","ignoreList":[]}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { createElement } from "react";
|
|
2
1
|
/**
|
|
3
2
|
* WordPress dependencies
|
|
4
3
|
*/
|
|
@@ -15,6 +14,8 @@ import { speak } from '@wordpress/a11y';
|
|
|
15
14
|
* Internal dependencies
|
|
16
15
|
*/
|
|
17
16
|
import { CATEGORY_SLUG } from './category-selector';
|
|
17
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
18
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
18
19
|
export default function RenamePatternCategoryModal({
|
|
19
20
|
category,
|
|
20
21
|
existingCategories,
|
|
@@ -102,40 +103,48 @@ export default function RenamePatternCategoryModal({
|
|
|
102
103
|
onClose();
|
|
103
104
|
setName('');
|
|
104
105
|
};
|
|
105
|
-
return
|
|
106
|
+
return /*#__PURE__*/_jsx(Modal, {
|
|
106
107
|
title: __('Rename'),
|
|
107
108
|
onRequestClose: onRequestClose,
|
|
108
|
-
...props
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
-
|
|
109
|
+
...props,
|
|
110
|
+
children: /*#__PURE__*/_jsx("form", {
|
|
111
|
+
onSubmit: onSave,
|
|
112
|
+
children: /*#__PURE__*/_jsxs(VStack, {
|
|
113
|
+
spacing: "5",
|
|
114
|
+
children: [/*#__PURE__*/_jsxs(VStack, {
|
|
115
|
+
spacing: "2",
|
|
116
|
+
children: [/*#__PURE__*/_jsx(TextControl, {
|
|
117
|
+
ref: textControlRef,
|
|
118
|
+
__nextHasNoMarginBottom: true,
|
|
119
|
+
__next40pxDefaultSize: true,
|
|
120
|
+
label: __('Name'),
|
|
121
|
+
value: name,
|
|
122
|
+
onChange: onChange,
|
|
123
|
+
"aria-describedby": validationMessageId,
|
|
124
|
+
required: true
|
|
125
|
+
}), validationMessage && /*#__PURE__*/_jsx("span", {
|
|
126
|
+
className: "patterns-rename-pattern-category-modal__validation-message",
|
|
127
|
+
id: validationMessageId,
|
|
128
|
+
children: validationMessage
|
|
129
|
+
})]
|
|
130
|
+
}), /*#__PURE__*/_jsxs(HStack, {
|
|
131
|
+
justify: "right",
|
|
132
|
+
children: [/*#__PURE__*/_jsx(Button, {
|
|
133
|
+
__next40pxDefaultSize: true,
|
|
134
|
+
variant: "tertiary",
|
|
135
|
+
onClick: onRequestClose,
|
|
136
|
+
children: __('Cancel')
|
|
137
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
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
|
+
});
|
|
140
149
|
}
|
|
141
150
|
//# sourceMappingURL=rename-pattern-category-modal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Modal","Button","TextControl","__experimentalHStack","HStack","__experimentalVStack","VStack","store","coreStore","useDispatch","useId","useRef","useState","decodeEntities","__","noticesStore","speak","CATEGORY_SLUG","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","createElement","title","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\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SACCA,KAAK,EACLC,MAAM,EACNC,WAAW,EACXC,oBAAoB,IAAIC,MAAM,EAC9BC,oBAAoB,IAAIC,MAAM,QACxB,uBAAuB;AAC9B,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,SAASC,KAAK,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BAAqB;IACrBK,OAAO,EAAC,SAAS;IACjBd,IAAI,EAAC,QAAQ;IACb,iBACC,CAAE3B,IAAI,IAAIA,IAAI,KAAKR,QAAQ,CAACQ,IAAI,IAAIE,QACpC;IACDyC,MAAM,EAAGzC;EAAU,GAEjBf,EAAE,CAAE,MAAO,CACN,CACD,CACD,CACH,CACA,CAAC;AAEV","ignoreList":[]}
|
|
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\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SACCA,KAAK,EACLC,MAAM,EACNC,WAAW,EACXC,oBAAoB,IAAIC,MAAM,EAC9BC,oBAAoB,IAAIC,MAAM,QACxB,uBAAuB;AAC9B,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,SAASC,KAAK,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,oBAAoB;AAC5D,SAASC,cAAc,QAAQ,0BAA0B;AACzD,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASP,KAAK,IAAIQ,YAAY,QAAQ,oBAAoB;AAC1D,SAASC,KAAK,QAAQ,iBAAiB;;AAEvC;AACA;AACA;AACA,SAASC,aAAa,QAAQ,qBAAqB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAAA,SAAAC,IAAA,IAAA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