@wordpress/patterns 2.0.2 → 2.0.4

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.
@@ -39,14 +39,15 @@ function addBindings(bindings) {
39
39
  }
40
40
  function PatternOverridesControls({
41
41
  attributes,
42
- setAttributes
42
+ setAttributes,
43
+ name: blockName
43
44
  }) {
44
45
  const controlId = (0, _element.useId)();
45
46
  const [showAllowOverridesModal, setShowAllowOverridesModal] = (0, _element.useState)(false);
46
47
  const [showDisallowOverridesModal, setShowDisallowOverridesModal] = (0, _element.useState)(false);
47
48
  const hasName = !!attributes.metadata?.name;
48
49
  const defaultBindings = attributes.metadata?.bindings?.__default;
49
- const allowOverrides = hasName && defaultBindings?.source === _constants.PATTERN_OVERRIDES_BINDING_SOURCE;
50
+ const hasOverrides = hasName && defaultBindings?.source === _constants.PATTERN_OVERRIDES_BINDING_SOURCE;
50
51
  const isConnectedToOtherSources = defaultBindings?.source && defaultBindings.source !== _constants.PATTERN_OVERRIDES_BINDING_SOURCE;
51
52
  function updateBindings(isChecked, customName) {
52
53
  const prevBindings = attributes?.metadata?.bindings;
@@ -67,26 +68,30 @@ function PatternOverridesControls({
67
68
  if (isConnectedToOtherSources) {
68
69
  return null;
69
70
  }
71
+ const hasUnsupportedImageAttributes = blockName === 'core/image' && (!!attributes.caption?.length || !!attributes.href?.length);
72
+ const helpText = !hasOverrides && hasUnsupportedImageAttributes ? (0, _i18n.__)(`Overrides currently don't support image captions or links. Remove the caption or link first before enabling overrides.`) : (0, _i18n.__)('Allow changes to this block throughout instances of this pattern.');
70
73
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
71
74
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.InspectorControls, {
72
75
  group: "advanced",
73
76
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.BaseControl, {
74
77
  id: controlId,
75
78
  label: (0, _i18n.__)('Overrides'),
76
- help: (0, _i18n.__)('Allow changes to this block throughout instances of this pattern.'),
79
+ help: helpText,
77
80
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
78
81
  __next40pxDefaultSize: true,
79
82
  className: "pattern-overrides-control__allow-overrides-button",
80
83
  variant: "secondary",
81
84
  "aria-haspopup": "dialog",
82
85
  onClick: () => {
83
- if (allowOverrides) {
86
+ if (hasOverrides) {
84
87
  setShowDisallowOverridesModal(true);
85
88
  } else {
86
89
  setShowAllowOverridesModal(true);
87
90
  }
88
91
  },
89
- children: allowOverrides ? (0, _i18n.__)('Disable overrides') : (0, _i18n.__)('Enable overrides')
92
+ disabled: !hasOverrides && hasUnsupportedImageAttributes,
93
+ __experimentalIsFocusable: true,
94
+ children: hasOverrides ? (0, _i18n.__)('Disable overrides') : (0, _i18n.__)('Enable overrides')
90
95
  })
91
96
  })
92
97
  }), showAllowOverridesModal && /*#__PURE__*/(0, _jsxRuntime.jsx)(_allowOverridesModal.AllowOverridesModal, {
@@ -1 +1 @@
1
- {"version":3,"names":["_element","require","_blockEditor","_components","_i18n","_constants","_allowOverridesModal","_jsxRuntime","removeBindings","bindings","updatedBindings","__default","Object","keys","length","undefined","addBindings","source","PATTERN_OVERRIDES_BINDING_SOURCE","PatternOverridesControls","attributes","setAttributes","controlId","useId","showAllowOverridesModal","setShowAllowOverridesModal","useState","showDisallowOverridesModal","setShowDisallowOverridesModal","hasName","metadata","name","defaultBindings","allowOverrides","isConnectedToOtherSources","updateBindings","isChecked","customName","prevBindings","updatedMetadata","jsxs","Fragment","children","jsx","InspectorControls","group","BaseControl","id","label","__","help","Button","__next40pxDefaultSize","className","variant","onClick","AllowOverridesModal","initialName","onClose","onSave","newName","DisallowOverridesModal","_default","exports","default"],"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":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;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B,CAAC,GACzB,IAAAA,QAAE,EAAE,kBAAmB;QAAC,CACpB;MAAC,CACG;IAAC,CACI,CAAC,EAElBzB,uBAAuB,iBACxB,IAAAjB,WAAA,CAAAoC,GAAA,EAACrC,oBAAA,CAAAkD,mBAAmB;MACnBC,WAAW,EAAGrC,UAAU,CAACU,QAAQ,EAAEC,IAAM;MACzC2B,OAAO,EAAGA,CAAA,KAAMjC,0BAA0B,CAAE,KAAM,CAAG;MACrDkC,MAAM,EAAKC,OAAO,IAAM;QACvBzB,cAAc,CAAE,IAAI,EAAEyB,OAAQ,CAAC;MAChC;IAAG,CACH,CACD,EACCjC,0BAA0B,iBAC3B,IAAApB,WAAA,CAAAoC,GAAA,EAACrC,oBAAA,CAAAuD,sBAAsB;MACtBH,OAAO,EAAGA,CAAA,KAAM9B,6BAA6B,CAAE,KAAM,CAAG;MACxD+B,MAAM,EAAGA,CAAA,KAAMxB,cAAc,CAAE,KAAM;IAAG,CACxC,CACD;EAAA,CACA,CAAC;AAEL;AAAC,IAAA2B,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEc7C,wBAAwB","ignoreList":[]}
1
+ {"version":3,"names":["_element","require","_blockEditor","_components","_i18n","_constants","_allowOverridesModal","_jsxRuntime","removeBindings","bindings","updatedBindings","__default","Object","keys","length","undefined","addBindings","source","PATTERN_OVERRIDES_BINDING_SOURCE","PatternOverridesControls","attributes","setAttributes","name","blockName","controlId","useId","showAllowOverridesModal","setShowAllowOverridesModal","useState","showDisallowOverridesModal","setShowDisallowOverridesModal","hasName","metadata","defaultBindings","hasOverrides","isConnectedToOtherSources","updateBindings","isChecked","customName","prevBindings","updatedMetadata","hasUnsupportedImageAttributes","caption","href","helpText","__","jsxs","Fragment","children","jsx","InspectorControls","group","BaseControl","id","label","help","Button","__next40pxDefaultSize","className","variant","onClick","disabled","__experimentalIsFocusable","AllowOverridesModal","initialName","onClose","onSave","newName","DisallowOverridesModal","_default","exports","default"],"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( {\n\tattributes,\n\tsetAttributes,\n\tname: blockName,\n} ) {\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 hasOverrides =\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\tconst hasUnsupportedImageAttributes =\n\t\tblockName === 'core/image' &&\n\t\t( !! attributes.caption?.length || !! attributes.href?.length );\n\n\tconst helpText =\n\t\t! hasOverrides && hasUnsupportedImageAttributes\n\t\t\t? __(\n\t\t\t\t\t`Overrides currently don't support image captions or links. Remove the caption or link first before enabling overrides.`\n\t\t\t )\n\t\t\t: __(\n\t\t\t\t\t'Allow changes to this block throughout instances of this pattern.'\n\t\t\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={ helpText }\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 ( hasOverrides ) {\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\tdisabled={\n\t\t\t\t\t\t\t! hasOverrides && hasUnsupportedImageAttributes\n\t\t\t\t\t\t}\n\t\t\t\t\t\t__experimentalIsFocusable\n\t\t\t\t\t>\n\t\t\t\t\t\t{ hasOverrides\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":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AAKA,IAAAI,UAAA,GAAAJ,OAAA;AACA,IAAAK,oBAAA,GAAAL,OAAA;AAGiC,IAAAM,WAAA,GAAAN,OAAA;AAfjC;AACA;AACA;;AAMA;AACA;AACA;;AAOA,SAASO,cAAcA,CAAEC,QAAQ,EAAG;EACnC,IAAIC,eAAe,GAAG;IAAE,GAAGD;EAAS,CAAC;EACrC,OAAOC,eAAe,CAACC,SAAS;EAChC,IAAK,CAAEC,MAAM,CAACC,IAAI,CAAEH,eAAgB,CAAC,CAACI,MAAM,EAAG;IAC9CJ,eAAe,GAAGK,SAAS;EAC5B;EACA,OAAOL,eAAe;AACvB;AAEA,SAASM,WAAWA,CAAEP,QAAQ,EAAG;EAChC,OAAO;IACN,GAAGA,QAAQ;IACXE,SAAS,EAAE;MAAEM,MAAM,EAAEC;IAAiC;EACvD,CAAC;AACF;AAEA,SAASC,wBAAwBA,CAAE;EAClCC,UAAU;EACVC,aAAa;EACbC,IAAI,EAAEC;AACP,CAAC,EAAG;EACH,MAAMC,SAAS,GAAG,IAAAC,cAAK,EAAC,CAAC;EACzB,MAAM,CAAE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CACH,CACD,EACCtC,0BAA0B,iBAC3B,IAAAtB,WAAA,CAAA0C,GAAA,EAAC3C,oBAAA,CAAA8D,sBAAsB;MACtBH,OAAO,EAAGA,CAAA,KAAMnC,6BAA6B,CAAE,KAAM,CAAG;MACxDoC,MAAM,EAAGA,CAAA,KAAM9B,cAAc,CAAE,KAAM;IAAG,CACxC,CACD;EAAA,CACA,CAAC;AAEL;AAAC,IAAAiC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEcpD,wBAAwB","ignoreList":[]}
@@ -34,14 +34,15 @@ function addBindings(bindings) {
34
34
  }
35
35
  function PatternOverridesControls({
36
36
  attributes,
37
- setAttributes
37
+ setAttributes,
38
+ name: blockName
38
39
  }) {
39
40
  const controlId = useId();
40
41
  const [showAllowOverridesModal, setShowAllowOverridesModal] = useState(false);
41
42
  const [showDisallowOverridesModal, setShowDisallowOverridesModal] = useState(false);
42
43
  const hasName = !!attributes.metadata?.name;
43
44
  const defaultBindings = attributes.metadata?.bindings?.__default;
44
- const allowOverrides = hasName && defaultBindings?.source === PATTERN_OVERRIDES_BINDING_SOURCE;
45
+ const hasOverrides = hasName && defaultBindings?.source === PATTERN_OVERRIDES_BINDING_SOURCE;
45
46
  const isConnectedToOtherSources = defaultBindings?.source && defaultBindings.source !== PATTERN_OVERRIDES_BINDING_SOURCE;
46
47
  function updateBindings(isChecked, customName) {
47
48
  const prevBindings = attributes?.metadata?.bindings;
@@ -62,26 +63,30 @@ function PatternOverridesControls({
62
63
  if (isConnectedToOtherSources) {
63
64
  return null;
64
65
  }
66
+ const hasUnsupportedImageAttributes = blockName === 'core/image' && (!!attributes.caption?.length || !!attributes.href?.length);
67
+ const helpText = !hasOverrides && hasUnsupportedImageAttributes ? __(`Overrides currently don't support image captions or links. Remove the caption or link first before enabling overrides.`) : __('Allow changes to this block throughout instances of this pattern.');
65
68
  return /*#__PURE__*/_jsxs(_Fragment, {
66
69
  children: [/*#__PURE__*/_jsx(InspectorControls, {
67
70
  group: "advanced",
68
71
  children: /*#__PURE__*/_jsx(BaseControl, {
69
72
  id: controlId,
70
73
  label: __('Overrides'),
71
- help: __('Allow changes to this block throughout instances of this pattern.'),
74
+ help: helpText,
72
75
  children: /*#__PURE__*/_jsx(Button, {
73
76
  __next40pxDefaultSize: true,
74
77
  className: "pattern-overrides-control__allow-overrides-button",
75
78
  variant: "secondary",
76
79
  "aria-haspopup": "dialog",
77
80
  onClick: () => {
78
- if (allowOverrides) {
81
+ if (hasOverrides) {
79
82
  setShowDisallowOverridesModal(true);
80
83
  } else {
81
84
  setShowAllowOverridesModal(true);
82
85
  }
83
86
  },
84
- children: allowOverrides ? __('Disable overrides') : __('Enable overrides')
87
+ disabled: !hasOverrides && hasUnsupportedImageAttributes,
88
+ __experimentalIsFocusable: true,
89
+ children: hasOverrides ? __('Disable overrides') : __('Enable overrides')
85
90
  })
86
91
  })
87
92
  }), showAllowOverridesModal && /*#__PURE__*/_jsx(AllowOverridesModal, {
@@ -1 +1 @@
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,MAAM,Q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A,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
+ {"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","name","blockName","controlId","showAllowOverridesModal","setShowAllowOverridesModal","showDisallowOverridesModal","setShowDisallowOverridesModal","hasName","metadata","defaultBindings","hasOverrides","isConnectedToOtherSources","updateBindings","isChecked","customName","prevBindings","updatedMetadata","hasUnsupportedImageAttributes","caption","href","helpText","children","group","id","label","help","__next40pxDefaultSize","className","variant","onClick","disabled","__experimentalIsFocusable","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( {\n\tattributes,\n\tsetAttributes,\n\tname: blockName,\n} ) {\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 hasOverrides =\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\tconst hasUnsupportedImageAttributes =\n\t\tblockName === 'core/image' &&\n\t\t( !! attributes.caption?.length || !! attributes.href?.length );\n\n\tconst helpText =\n\t\t! hasOverrides && hasUnsupportedImageAttributes\n\t\t\t? __(\n\t\t\t\t\t`Overrides currently don't support image captions or links. Remove the caption or link first before enabling overrides.`\n\t\t\t )\n\t\t\t: __(\n\t\t\t\t\t'Allow changes to this block throughout instances of this pattern.'\n\t\t\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={ helpText }\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 ( hasOverrides ) {\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\tdisabled={\n\t\t\t\t\t\t\t! hasOverrides && hasUnsupportedImageAttributes\n\t\t\t\t\t\t}\n\t\t\t\t\t\t__experimentalIsFocusable\n\t\t\t\t\t>\n\t\t\t\t\t\t{ hasOverrides\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,MAAM,QAAQ,uBAAuB;AAC3D,SAASC,EAAE,QAAQ,iBAAiB;;AAEpC;AACA;AACA;AACA,SAASC,gCAAgC,QAAQ,cAAc;AAC/D,SACCC,mBAAmB,EACnBC,sBAAsB,QAChB,yBAAyB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAAA,SAAAC,QAAA,IAAAC,SAAA;AAAA,SAAAC,IAAA,IAAAC,KAAA;AAEjC,SAASC,cAAcA,CAAEC,QAAQ,EAAG;EACnC,IAAIC,eAAe,GAAG;IAAE,GAAGD;EAAS,CAAC;EACrC,OAAOC,eAAe,CAACC,SAAS;EAChC,IAAK,CAAEC,MAAM,CAACC,IAAI,CAAEH,eAAgB,CAAC,CAACI,MAAM,EAAG;IAC9CJ,eAAe,GAAGK,SAAS;EAC5B;EACA,OAAOL,eAAe;AACvB;AAEA,SAASM,WAAWA,CAAEP,QAAQ,EAAG;EAChC,OAAO;IACN,GAAGA,QAAQ;IACXE,SAAS,EAAE;MAAEM,MAAM,EAAElB;IAAiC;EACvD,CAAC;AACF;AAEA,SAASmB,wBAAwBA,CAAE;EAClCC,UAAU;EACVC,aAAa;EACbC,IAAI,EAAEC;AACP,CAAC,EAAG;EACH,MAAMC,SAAS,GAAG7B,KAAK,CAAC,CAAC;EACzB,MAAM,CAAE8B,uBAAuB,EAAEC,0BAA0B,CAAE,GAC5DhC,QAAQ,CAAE,KAAM,CAAC;EAClB,MAAM,CAAEiC,0BAA0B,EAAEC,6BAA6B,CAAE,GAClElC,QAAQ,CAAE,KAAM,CAAC;EA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P,WAAW;QACXgD,EAAE,EAAGrB,SAAW;QAChBsB,KAAK,EAAG/C,EAAE,CAAE,WAAY,CAAG;QAC3BgD,IAAI,EAAGL,QAAU;QAAAC,QAAA,eAEjBvC,IAAA,CAACN,MAAM;UACNkD,qBAAqB;UACrBC,SAAS,EAAC,mDAAmD;UAC7DC,OAAO,EAAC,WAAW;UACnB,iBAAc,QAAQ;UACtBC,OAAO,EAAGA,CAAA,KAAM;YACf,IAAKnB,YAAY,EAAG;cACnBJ,6BAA6B,CAAE,IAAK,CAAC;YACtC,CAAC,MAAM;cACNF,0BAA0B,CAAE,IAAK,CAAC;YACnC;UACD,CAAG;UACH0B,QAAQ,EACP,CAAEpB,YAAY,IAAIO,6BAClB;UACDc,yBAAyB;UAAAV,QAAA,EAEvBX,YAAY,GACXjC,EAAE,CAAE,mBAAoB,CAAC,GACzBA,EAAE,CAAE,kBAAmB;QAAC,CACpB;MAAC,CACG;IAAC,CACI,CAAC,EAElB0B,uBAAuB,iBACxBrB,IAAA,CAACH,mBAAmB;MACnBqD,WAAW,EAAGlC,UAAU,CAACU,QAAQ,EAAER,IAAM;MACzCiC,OAAO,EAAGA,CAAA,KAAM7B,0BAA0B,CAAE,KAAM,CAAG;MACrD8B,MAAM,EAAKC,OAAO,IAAM;QACvBvB,cAAc,CAAE,IAAI,EAAEuB,OAAQ,CAAC;MAChC;IAAG,CACH,CACD,EACC9B,0BAA0B,iBAC3BvB,IAAA,CAACF,sBAAsB;MACtBqD,OAAO,EAAGA,CAAA,KAAM3B,6BAA6B,CAAE,KAAM,CAAG;MACxD4B,MAAM,EAAGA,CAAA,KAAMtB,cAAc,CAAE,KAAM;IAAG,CACxC,CACD;EAAA,CACA,CAAC;AAEL;AAEA,eAAef,wBAAwB","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/patterns",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "description": "Management of user pattern editing.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -33,16 +33,16 @@
33
33
  "dependencies": {
34
34
  "@babel/runtime": "^7.16.0",
35
35
  "@wordpress/a11y": "^4.0.1",
36
- "@wordpress/block-editor": "^13.0.2",
37
- "@wordpress/blocks": "^13.0.2",
38
- "@wordpress/components": "^28.0.2",
36
+ "@wordpress/block-editor": "^13.0.4",
37
+ "@wordpress/blocks": "^13.0.3",
38
+ "@wordpress/components": "^28.0.3",
39
39
  "@wordpress/compose": "^7.0.1",
40
- "@wordpress/core-data": "^7.0.2",
40
+ "@wordpress/core-data": "^7.0.4",
41
41
  "@wordpress/data": "^10.0.2",
42
42
  "@wordpress/element": "^6.0.1",
43
43
  "@wordpress/html-entities": "^4.0.1",
44
44
  "@wordpress/i18n": "^5.0.1",
45
- "@wordpress/icons": "^10.0.1",
45
+ "@wordpress/icons": "^10.0.2",
46
46
  "@wordpress/notices": "^5.0.2",
47
47
  "@wordpress/private-apis": "^1.0.2",
48
48
  "@wordpress/url": "^4.0.1"
@@ -54,5 +54,5 @@
54
54
  "publishConfig": {
55
55
  "access": "public"
56
56
  },
57
- "gitHead": "a68c6b5ef53956cccf4961d53d79b6af7e00ae60"
57
+ "gitHead": "85486692a3e48b7d863226cf895a21d787434921"
58
58
  }
@@ -31,7 +31,11 @@ function addBindings( bindings ) {
31
31
  };
32
32
  }
33
33
 
34
- function PatternOverridesControls( { attributes, setAttributes } ) {
34
+ function PatternOverridesControls( {
35
+ attributes,
36
+ setAttributes,
37
+ name: blockName,
38
+ } ) {
35
39
  const controlId = useId();
36
40
  const [ showAllowOverridesModal, setShowAllowOverridesModal ] =
37
41
  useState( false );
@@ -40,7 +44,7 @@ function PatternOverridesControls( { attributes, setAttributes } ) {
40
44
 
41
45
  const hasName = !! attributes.metadata?.name;
42
46
  const defaultBindings = attributes.metadata?.bindings?.__default;
43
- const allowOverrides =
47
+ const hasOverrides =
44
48
  hasName && defaultBindings?.source === PATTERN_OVERRIDES_BINDING_SOURCE;
45
49
  const isConnectedToOtherSources =
46
50
  defaultBindings?.source &&
@@ -71,15 +75,26 @@ function PatternOverridesControls( { attributes, setAttributes } ) {
71
75
  return null;
72
76
  }
73
77
 
78
+ const hasUnsupportedImageAttributes =
79
+ blockName === 'core/image' &&
80
+ ( !! attributes.caption?.length || !! attributes.href?.length );
81
+
82
+ const helpText =
83
+ ! hasOverrides && hasUnsupportedImageAttributes
84
+ ? __(
85
+ `Overrides currently don't support image captions or links. Remove the caption or link first before enabling overrides.`
86
+ )
87
+ : __(
88
+ 'Allow changes to this block throughout instances of this pattern.'
89
+ );
90
+
74
91
  return (
75
92
  <>
76
93
  <InspectorControls group="advanced">
77
94
  <BaseControl
78
95
  id={ controlId }
79
96
  label={ __( 'Overrides' ) }
80
- help={ __(
81
- 'Allow changes to this block throughout instances of this pattern.'
82
- ) }
97
+ help={ helpText }
83
98
  >
84
99
  <Button
85
100
  __next40pxDefaultSize
@@ -87,14 +102,18 @@ function PatternOverridesControls( { attributes, setAttributes } ) {
87
102
  variant="secondary"
88
103
  aria-haspopup="dialog"
89
104
  onClick={ () => {
90
- if ( allowOverrides ) {
105
+ if ( hasOverrides ) {
91
106
  setShowDisallowOverridesModal( true );
92
107
  } else {
93
108
  setShowAllowOverridesModal( true );
94
109
  }
95
110
  } }
111
+ disabled={
112
+ ! hasOverrides && hasUnsupportedImageAttributes
113
+ }
114
+ __experimentalIsFocusable
96
115
  >
97
- { allowOverrides
116
+ { hasOverrides
98
117
  ? __( 'Disable overrides' )
99
118
  : __( 'Enable overrides' ) }
100
119
  </Button>