@wordpress/patterns 2.34.0 → 2.35.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.
Files changed (104) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/api/index.js +2 -0
  3. package/build/api/index.js.map +1 -1
  4. package/build/components/allow-overrides-modal.js +3 -1
  5. package/build/components/allow-overrides-modal.js.map +1 -1
  6. package/build/components/category-selector.js +5 -3
  7. package/build/components/category-selector.js.map +1 -1
  8. package/build/components/create-pattern-modal.js +3 -1
  9. package/build/components/create-pattern-modal.js.map +1 -1
  10. package/build/components/duplicate-pattern-modal.js +3 -1
  11. package/build/components/duplicate-pattern-modal.js.map +1 -1
  12. package/build/components/index.js +3 -1
  13. package/build/components/index.js.map +1 -1
  14. package/build/components/overrides-panel.js +4 -2
  15. package/build/components/overrides-panel.js.map +1 -1
  16. package/build/components/pattern-convert-button.js +3 -1
  17. package/build/components/pattern-convert-button.js.map +1 -1
  18. package/build/components/pattern-overrides-controls.js +3 -1
  19. package/build/components/pattern-overrides-controls.js.map +1 -1
  20. package/build/components/patterns-manage-button.js +4 -2
  21. package/build/components/patterns-manage-button.js.map +2 -2
  22. package/build/components/rename-pattern-category-modal.js +3 -1
  23. package/build/components/rename-pattern-category-modal.js.map +1 -1
  24. package/build/components/rename-pattern-modal.js +3 -1
  25. package/build/components/rename-pattern-modal.js.map +1 -1
  26. package/build/components/reset-overrides-control.js +4 -2
  27. package/build/components/reset-overrides-control.js.map +1 -1
  28. package/build/constants.js +9 -7
  29. package/build/constants.js.map +1 -1
  30. package/build/index.js +2 -0
  31. package/build/index.js.map +1 -1
  32. package/build/lock-unlock.js +3 -1
  33. package/build/lock-unlock.js.map +1 -1
  34. package/build/private-apis.js +3 -3
  35. package/build/private-apis.js.map +3 -3
  36. package/build/private-hooks.js +2 -0
  37. package/build/private-hooks.js.map +1 -1
  38. package/build/store/actions.js +5 -3
  39. package/build/store/actions.js.map +1 -1
  40. package/build/store/constants.js +3 -1
  41. package/build/store/constants.js.map +1 -1
  42. package/build/store/index.js +4 -2
  43. package/build/store/index.js.map +1 -1
  44. package/build/store/reducer.js +2 -0
  45. package/build/store/reducer.js.map +1 -1
  46. package/build/store/selectors.js +2 -0
  47. package/build/store/selectors.js.map +1 -1
  48. package/build-module/api/index.js +1 -0
  49. package/build-module/api/index.js.map +1 -1
  50. package/build-module/components/allow-overrides-modal.js +2 -1
  51. package/build-module/components/allow-overrides-modal.js.map +1 -1
  52. package/build-module/components/category-selector.js +4 -3
  53. package/build-module/components/category-selector.js.map +1 -1
  54. package/build-module/components/create-pattern-modal.js +2 -1
  55. package/build-module/components/create-pattern-modal.js.map +1 -1
  56. package/build-module/components/duplicate-pattern-modal.js +2 -1
  57. package/build-module/components/duplicate-pattern-modal.js.map +1 -1
  58. package/build-module/components/index.js +2 -1
  59. package/build-module/components/index.js.map +1 -1
  60. package/build-module/components/overrides-panel.js +3 -2
  61. package/build-module/components/overrides-panel.js.map +1 -1
  62. package/build-module/components/pattern-convert-button.js +2 -1
  63. package/build-module/components/pattern-convert-button.js.map +1 -1
  64. package/build-module/components/pattern-overrides-controls.js +2 -1
  65. package/build-module/components/pattern-overrides-controls.js.map +1 -1
  66. package/build-module/components/patterns-manage-button.js +3 -2
  67. package/build-module/components/patterns-manage-button.js.map +2 -2
  68. package/build-module/components/rename-pattern-category-modal.js +2 -1
  69. package/build-module/components/rename-pattern-category-modal.js.map +1 -1
  70. package/build-module/components/rename-pattern-modal.js +2 -1
  71. package/build-module/components/rename-pattern-modal.js.map +1 -1
  72. package/build-module/components/reset-overrides-control.js +3 -2
  73. package/build-module/components/reset-overrides-control.js.map +1 -1
  74. package/build-module/constants.js +8 -7
  75. package/build-module/constants.js.map +1 -1
  76. package/build-module/index.js +1 -0
  77. package/build-module/index.js.map +1 -1
  78. package/build-module/lock-unlock.js +2 -1
  79. package/build-module/lock-unlock.js.map +1 -1
  80. package/build-module/private-apis.js +2 -3
  81. package/build-module/private-apis.js.map +2 -2
  82. package/build-module/private-hooks.js +1 -0
  83. package/build-module/private-hooks.js.map +1 -1
  84. package/build-module/store/actions.js +4 -3
  85. package/build-module/store/actions.js.map +1 -1
  86. package/build-module/store/constants.js +2 -1
  87. package/build-module/store/constants.js.map +1 -1
  88. package/build-module/store/index.js +3 -2
  89. package/build-module/store/index.js.map +1 -1
  90. package/build-module/store/reducer.js +1 -0
  91. package/build-module/store/reducer.js.map +1 -1
  92. package/build-module/store/selectors.js +1 -0
  93. package/build-module/store/selectors.js.map +1 -1
  94. package/build-style/style-rtl.css +0 -13
  95. package/build-style/style.css +0 -13
  96. package/package.json +17 -17
  97. package/src/components/patterns-manage-button.js +1 -1
  98. package/src/components/style.scss +0 -14
  99. package/src/private-apis.js +0 -2
  100. package/build/components/pattern-overrides-block-controls.js +0 -130
  101. package/build/components/pattern-overrides-block-controls.js.map +0 -7
  102. package/build-module/components/pattern-overrides-block-controls.js +0 -120
  103. package/build-module/components/pattern-overrides-block-controls.js.map +0 -7
  104. package/src/components/pattern-overrides-block-controls.js +0 -155
@@ -142,17 +142,4 @@
142
142
  .pattern-overrides-control__allow-overrides-button {
143
143
  width: 100%;
144
144
  justify-content: center;
145
- }
146
-
147
- .patterns-pattern-overrides-toolbar-indicator__popover .components-popover__content {
148
- min-width: 260px;
149
- padding: 16px;
150
- }
151
-
152
- .patterns-pattern-overrides-toolbar-indicator .patterns-pattern-overrides-toolbar-indicator-icon.has-colors svg {
153
- fill: var(--wp-block-synced-color);
154
- }
155
-
156
- .editor-collapsible-block-toolbar .patterns-pattern-overrides-toolbar-indicator {
157
- height: 32px;
158
145
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/patterns",
3
- "version": "2.34.0",
3
+ "version": "2.35.0",
4
4
  "description": "Management of user pattern editing.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -39,21 +39,21 @@
39
39
  "{src,build,build-module}/{index.js,store/index.js,hooks/**}"
40
40
  ],
41
41
  "dependencies": {
42
- "@wordpress/a11y": "^4.34.0",
43
- "@wordpress/base-styles": "^6.10.0",
44
- "@wordpress/block-editor": "^15.7.0",
45
- "@wordpress/blocks": "^15.7.0",
46
- "@wordpress/components": "^30.7.0",
47
- "@wordpress/compose": "^7.34.0",
48
- "@wordpress/core-data": "^7.34.0",
49
- "@wordpress/data": "^10.34.0",
50
- "@wordpress/element": "^6.34.0",
51
- "@wordpress/html-entities": "^4.34.0",
52
- "@wordpress/i18n": "^6.7.0",
53
- "@wordpress/icons": "^11.1.0",
54
- "@wordpress/notices": "^5.34.0",
55
- "@wordpress/private-apis": "^1.34.0",
56
- "@wordpress/url": "^4.34.0"
42
+ "@wordpress/a11y": "^4.35.0",
43
+ "@wordpress/base-styles": "^6.11.0",
44
+ "@wordpress/block-editor": "^15.8.0",
45
+ "@wordpress/blocks": "^15.8.0",
46
+ "@wordpress/components": "^30.8.0",
47
+ "@wordpress/compose": "^7.35.0",
48
+ "@wordpress/core-data": "^7.35.0",
49
+ "@wordpress/data": "^10.35.0",
50
+ "@wordpress/element": "^6.35.0",
51
+ "@wordpress/html-entities": "^4.35.0",
52
+ "@wordpress/i18n": "^6.8.0",
53
+ "@wordpress/icons": "^11.2.0",
54
+ "@wordpress/notices": "^5.35.0",
55
+ "@wordpress/private-apis": "^1.35.0",
56
+ "@wordpress/url": "^4.35.0"
57
57
  },
58
58
  "peerDependencies": {
59
59
  "react": "^18.0.0",
@@ -62,5 +62,5 @@
62
62
  "publishConfig": {
63
63
  "access": "public"
64
64
  },
65
- "gitHead": "ceebff807958d2e8fc755b5a20473939c78b4d1d"
65
+ "gitHead": "77aa1f194edceafe8ac2a1b9438bf84b557e76e3"
66
66
  }
@@ -103,7 +103,7 @@ function PatternsManageButton( { clientId } ) {
103
103
  }
104
104
  } }
105
105
  >
106
- { __( 'Detach' ) }
106
+ { __( 'Disconnect pattern' ) }
107
107
  </MenuItem>
108
108
  ) }
109
109
  <MenuItem href={ managePatternsUrl }>
@@ -48,17 +48,3 @@
48
48
  width: 100%;
49
49
  justify-content: center;
50
50
  }
51
-
52
-
53
- .patterns-pattern-overrides-toolbar-indicator__popover .components-popover__content {
54
- min-width: 260px;
55
- padding: $grid-unit-20;
56
- }
57
-
58
- .patterns-pattern-overrides-toolbar-indicator .patterns-pattern-overrides-toolbar-indicator-icon.has-colors svg {
59
- fill: var(--wp-block-synced-color);
60
- }
61
-
62
- .editor-collapsible-block-toolbar .patterns-pattern-overrides-toolbar-indicator {
63
- height: 32px;
64
- }
@@ -17,7 +17,6 @@ import PatternsMenuItems from './components';
17
17
  import RenamePatternCategoryModal from './components/rename-pattern-category-modal';
18
18
  import PatternOverridesControls from './components/pattern-overrides-controls';
19
19
  import ResetOverridesControl from './components/reset-overrides-control';
20
- import PatternOverridesBlockControls from './components/pattern-overrides-block-controls';
21
20
  import { useAddPatternCategory } from './private-hooks';
22
21
  import {
23
22
  PATTERN_TYPES,
@@ -42,7 +41,6 @@ lock( privateApis, {
42
41
  RenamePatternCategoryModal,
43
42
  PatternOverridesControls,
44
43
  ResetOverridesControl,
45
- PatternOverridesBlockControls,
46
44
  useAddPatternCategory,
47
45
  PATTERN_TYPES,
48
46
  PATTERN_DEFAULT_CATEGORY,
@@ -1,130 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var pattern_overrides_block_controls_exports = {};
19
- __export(pattern_overrides_block_controls_exports, {
20
- default: () => PatternOverridesBlockControls
21
- });
22
- module.exports = __toCommonJS(pattern_overrides_block_controls_exports);
23
- var import_jsx_runtime = require("react/jsx-runtime");
24
- var import_element = require("@wordpress/element");
25
- var import_i18n = require("@wordpress/i18n");
26
- var import_components = require("@wordpress/components");
27
- var import_blocks = require("@wordpress/blocks");
28
- var import_data = require("@wordpress/data");
29
- var import_icons = require("@wordpress/icons");
30
- var import_block_editor = require("@wordpress/block-editor");
31
- var import_lock_unlock = require("../lock-unlock");
32
- var import_constants = require("../constants");
33
- const { useBlockDisplayTitle } = (0, import_lock_unlock.unlock)(import_block_editor.privateApis);
34
- function PatternOverridesToolbarIndicator({ clientIds }) {
35
- const isSingleBlockSelected = clientIds.length === 1;
36
- const { icon, firstBlockName } = (0, import_data.useSelect)(
37
- (select) => {
38
- const { getBlockAttributes, getBlockNamesByClientId } = select(import_block_editor.store);
39
- const { getBlockType, getActiveBlockVariation } = select(import_blocks.store);
40
- const blockTypeNames = getBlockNamesByClientId(clientIds);
41
- const _firstBlockTypeName = blockTypeNames[0];
42
- const firstBlockType = getBlockType(_firstBlockTypeName);
43
- let _icon;
44
- if (isSingleBlockSelected) {
45
- const match = getActiveBlockVariation(
46
- _firstBlockTypeName,
47
- getBlockAttributes(clientIds[0])
48
- );
49
- _icon = match?.icon || firstBlockType.icon;
50
- } else {
51
- const isSelectionOfSameType = new Set(blockTypeNames).size === 1;
52
- _icon = isSelectionOfSameType ? firstBlockType.icon : import_icons.copy;
53
- }
54
- return {
55
- icon: _icon,
56
- firstBlockName: getBlockAttributes(clientIds[0]).metadata.name
57
- };
58
- },
59
- [clientIds, isSingleBlockSelected]
60
- );
61
- const firstBlockTitle = useBlockDisplayTitle({
62
- clientId: clientIds[0],
63
- maximumLength: 35
64
- });
65
- const blockDescription = isSingleBlockSelected ? (0, import_i18n.sprintf)(
66
- /* translators: 1: The block type's name. 2: The block's user-provided name (the same as the override name). */
67
- (0, import_i18n.__)('This %1$s is editable using the "%2$s" override.'),
68
- firstBlockTitle.toLowerCase(),
69
- firstBlockName
70
- ) : (0, import_i18n.__)("These blocks are editable using overrides.");
71
- const descriptionId = (0, import_element.useId)();
72
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.ToolbarItem, { children: (toggleProps) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
73
- import_components.DropdownMenu,
74
- {
75
- className: "patterns-pattern-overrides-toolbar-indicator",
76
- label: firstBlockTitle,
77
- popoverProps: {
78
- placement: "bottom-start",
79
- className: "patterns-pattern-overrides-toolbar-indicator__popover"
80
- },
81
- icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
82
- import_block_editor.BlockIcon,
83
- {
84
- icon,
85
- className: "patterns-pattern-overrides-toolbar-indicator-icon",
86
- showColors: true
87
- }
88
- ) }),
89
- toggleProps: {
90
- description: blockDescription,
91
- ...toggleProps
92
- },
93
- menuProps: {
94
- orientation: "both",
95
- "aria-describedby": descriptionId
96
- },
97
- children: () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.__experimentalText, { id: descriptionId, children: blockDescription })
98
- }
99
- ) });
100
- }
101
- function PatternOverridesBlockControls() {
102
- const { clientIds, hasPatternOverrides, hasParentPattern } = (0, import_data.useSelect)(
103
- (select) => {
104
- const {
105
- getBlockAttributes,
106
- getSelectedBlockClientIds,
107
- getBlockParentsByBlockName
108
- } = select(import_block_editor.store);
109
- const selectedClientIds = getSelectedBlockClientIds();
110
- const _hasPatternOverrides = selectedClientIds.every(
111
- (clientId) => Object.values(
112
- getBlockAttributes(clientId)?.metadata?.bindings ?? {}
113
- ).some(
114
- (binding) => binding?.source === import_constants.PATTERN_OVERRIDES_BINDING_SOURCE
115
- )
116
- );
117
- const _hasParentPattern = selectedClientIds.every(
118
- (clientId) => getBlockParentsByBlockName(clientId, "core/block", true).length > 0
119
- );
120
- return {
121
- clientIds: selectedClientIds,
122
- hasPatternOverrides: _hasPatternOverrides,
123
- hasParentPattern: _hasParentPattern
124
- };
125
- },
126
- []
127
- );
128
- return hasPatternOverrides && hasParentPattern ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_block_editor.BlockControls, { group: "parent", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PatternOverridesToolbarIndicator, { clientIds }) }) : null;
129
- }
130
- //# sourceMappingURL=pattern-overrides-block-controls.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/components/pattern-overrides-block-controls.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useId } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\tDropdownMenu,\n\tToolbarItem,\n\t__experimentalText as Text,\n} from '@wordpress/components';\nimport { store as blocksStore } from '@wordpress/blocks';\nimport { useSelect } from '@wordpress/data';\nimport { copy } from '@wordpress/icons';\nimport {\n\tstore as blockEditorStore,\n\tBlockIcon,\n\tprivateApis as blockEditorPrivateApis,\n\tBlockControls,\n} from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../lock-unlock';\nimport { PATTERN_OVERRIDES_BINDING_SOURCE } from '../constants';\n\nconst { useBlockDisplayTitle } = unlock( blockEditorPrivateApis );\n\nfunction PatternOverridesToolbarIndicator( { clientIds } ) {\n\tconst isSingleBlockSelected = clientIds.length === 1;\n\tconst { icon, firstBlockName } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlockAttributes, getBlockNamesByClientId } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst { getBlockType, getActiveBlockVariation } =\n\t\t\t\tselect( blocksStore );\n\t\t\tconst blockTypeNames = getBlockNamesByClientId( clientIds );\n\t\t\tconst _firstBlockTypeName = blockTypeNames[ 0 ];\n\t\t\tconst firstBlockType = getBlockType( _firstBlockTypeName );\n\t\t\tlet _icon;\n\t\t\tif ( isSingleBlockSelected ) {\n\t\t\t\tconst match = getActiveBlockVariation(\n\t\t\t\t\t_firstBlockTypeName,\n\t\t\t\t\tgetBlockAttributes( clientIds[ 0 ] )\n\t\t\t\t);\n\t\t\t\t// Take into account active block variations.\n\t\t\t\t_icon = match?.icon || firstBlockType.icon;\n\t\t\t} else {\n\t\t\t\tconst isSelectionOfSameType =\n\t\t\t\t\tnew Set( blockTypeNames ).size === 1;\n\t\t\t\t// When selection consists of blocks of multiple types, display an\n\t\t\t\t// appropriate icon to communicate the non-uniformity.\n\t\t\t\t_icon = isSelectionOfSameType ? firstBlockType.icon : copy;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\ticon: _icon,\n\t\t\t\tfirstBlockName: getBlockAttributes( clientIds[ 0 ] ).metadata\n\t\t\t\t\t.name,\n\t\t\t};\n\t\t},\n\t\t[ clientIds, isSingleBlockSelected ]\n\t);\n\tconst firstBlockTitle = useBlockDisplayTitle( {\n\t\tclientId: clientIds[ 0 ],\n\t\tmaximumLength: 35,\n\t} );\n\n\tconst blockDescription = isSingleBlockSelected\n\t\t? sprintf(\n\t\t\t\t/* translators: 1: The block type's name. 2: The block's user-provided name (the same as the override name). */\n\t\t\t\t__( 'This %1$s is editable using the \"%2$s\" override.' ),\n\t\t\t\tfirstBlockTitle.toLowerCase(),\n\t\t\t\tfirstBlockName\n\t\t )\n\t\t: __( 'These blocks are editable using overrides.' );\n\n\tconst descriptionId = useId();\n\n\treturn (\n\t\t<ToolbarItem>\n\t\t\t{ ( toggleProps ) => (\n\t\t\t\t<DropdownMenu\n\t\t\t\t\tclassName=\"patterns-pattern-overrides-toolbar-indicator\"\n\t\t\t\t\tlabel={ firstBlockTitle }\n\t\t\t\t\tpopoverProps={ {\n\t\t\t\t\t\tplacement: 'bottom-start',\n\t\t\t\t\t\tclassName:\n\t\t\t\t\t\t\t'patterns-pattern-overrides-toolbar-indicator__popover',\n\t\t\t\t\t} }\n\t\t\t\t\ticon={\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<BlockIcon\n\t\t\t\t\t\t\t\ticon={ icon }\n\t\t\t\t\t\t\t\tclassName=\"patterns-pattern-overrides-toolbar-indicator-icon\"\n\t\t\t\t\t\t\t\tshowColors\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\ttoggleProps={ {\n\t\t\t\t\t\tdescription: blockDescription,\n\t\t\t\t\t\t...toggleProps,\n\t\t\t\t\t} }\n\t\t\t\t\tmenuProps={ {\n\t\t\t\t\t\torientation: 'both',\n\t\t\t\t\t\t'aria-describedby': descriptionId,\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t{ () => (\n\t\t\t\t\t\t<Text id={ descriptionId }>{ blockDescription }</Text>\n\t\t\t\t\t) }\n\t\t\t\t</DropdownMenu>\n\t\t\t) }\n\t\t</ToolbarItem>\n\t);\n}\n\nexport default function PatternOverridesBlockControls() {\n\tconst { clientIds, hasPatternOverrides, hasParentPattern } = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlockAttributes,\n\t\t\t\tgetSelectedBlockClientIds,\n\t\t\t\tgetBlockParentsByBlockName,\n\t\t\t} = select( blockEditorStore );\n\t\t\tconst selectedClientIds = getSelectedBlockClientIds();\n\t\t\tconst _hasPatternOverrides = selectedClientIds.every(\n\t\t\t\t( clientId ) =>\n\t\t\t\t\tObject.values(\n\t\t\t\t\t\tgetBlockAttributes( clientId )?.metadata?.bindings ?? {}\n\t\t\t\t\t).some(\n\t\t\t\t\t\t( binding ) =>\n\t\t\t\t\t\t\tbinding?.source === PATTERN_OVERRIDES_BINDING_SOURCE\n\t\t\t\t\t)\n\t\t\t);\n\t\t\tconst _hasParentPattern = selectedClientIds.every(\n\t\t\t\t( clientId ) =>\n\t\t\t\t\tgetBlockParentsByBlockName( clientId, 'core/block', true )\n\t\t\t\t\t\t.length > 0\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tclientIds: selectedClientIds,\n\t\t\t\thasPatternOverrides: _hasPatternOverrides,\n\t\t\t\thasParentPattern: _hasParentPattern,\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\n\treturn hasPatternOverrides && hasParentPattern ? (\n\t\t<BlockControls group=\"parent\">\n\t\t\t<PatternOverridesToolbarIndicator clientIds={ clientIds } />\n\t\t</BlockControls>\n\t) : null;\n}\n"],
5
- "mappings": "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",
6
- "names": ["blockEditorPrivateApis", "blockEditorStore", "blocksStore", "Text"]
7
- }
@@ -1,120 +0,0 @@
1
- import { Fragment, jsx } from "react/jsx-runtime";
2
- import { useId } from "@wordpress/element";
3
- import { __, sprintf } from "@wordpress/i18n";
4
- import {
5
- DropdownMenu,
6
- ToolbarItem,
7
- __experimentalText as Text
8
- } from "@wordpress/components";
9
- import { store as blocksStore } from "@wordpress/blocks";
10
- import { useSelect } from "@wordpress/data";
11
- import { copy } from "@wordpress/icons";
12
- import {
13
- store as blockEditorStore,
14
- BlockIcon,
15
- privateApis as blockEditorPrivateApis,
16
- BlockControls
17
- } from "@wordpress/block-editor";
18
- import { unlock } from "../lock-unlock";
19
- import { PATTERN_OVERRIDES_BINDING_SOURCE } from "../constants";
20
- const { useBlockDisplayTitle } = unlock(blockEditorPrivateApis);
21
- function PatternOverridesToolbarIndicator({ clientIds }) {
22
- const isSingleBlockSelected = clientIds.length === 1;
23
- const { icon, firstBlockName } = useSelect(
24
- (select) => {
25
- const { getBlockAttributes, getBlockNamesByClientId } = select(blockEditorStore);
26
- const { getBlockType, getActiveBlockVariation } = select(blocksStore);
27
- const blockTypeNames = getBlockNamesByClientId(clientIds);
28
- const _firstBlockTypeName = blockTypeNames[0];
29
- const firstBlockType = getBlockType(_firstBlockTypeName);
30
- let _icon;
31
- if (isSingleBlockSelected) {
32
- const match = getActiveBlockVariation(
33
- _firstBlockTypeName,
34
- getBlockAttributes(clientIds[0])
35
- );
36
- _icon = match?.icon || firstBlockType.icon;
37
- } else {
38
- const isSelectionOfSameType = new Set(blockTypeNames).size === 1;
39
- _icon = isSelectionOfSameType ? firstBlockType.icon : copy;
40
- }
41
- return {
42
- icon: _icon,
43
- firstBlockName: getBlockAttributes(clientIds[0]).metadata.name
44
- };
45
- },
46
- [clientIds, isSingleBlockSelected]
47
- );
48
- const firstBlockTitle = useBlockDisplayTitle({
49
- clientId: clientIds[0],
50
- maximumLength: 35
51
- });
52
- const blockDescription = isSingleBlockSelected ? sprintf(
53
- /* translators: 1: The block type's name. 2: The block's user-provided name (the same as the override name). */
54
- __('This %1$s is editable using the "%2$s" override.'),
55
- firstBlockTitle.toLowerCase(),
56
- firstBlockName
57
- ) : __("These blocks are editable using overrides.");
58
- const descriptionId = useId();
59
- return /* @__PURE__ */ jsx(ToolbarItem, { children: (toggleProps) => /* @__PURE__ */ jsx(
60
- DropdownMenu,
61
- {
62
- className: "patterns-pattern-overrides-toolbar-indicator",
63
- label: firstBlockTitle,
64
- popoverProps: {
65
- placement: "bottom-start",
66
- className: "patterns-pattern-overrides-toolbar-indicator__popover"
67
- },
68
- icon: /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(
69
- BlockIcon,
70
- {
71
- icon,
72
- className: "patterns-pattern-overrides-toolbar-indicator-icon",
73
- showColors: true
74
- }
75
- ) }),
76
- toggleProps: {
77
- description: blockDescription,
78
- ...toggleProps
79
- },
80
- menuProps: {
81
- orientation: "both",
82
- "aria-describedby": descriptionId
83
- },
84
- children: () => /* @__PURE__ */ jsx(Text, { id: descriptionId, children: blockDescription })
85
- }
86
- ) });
87
- }
88
- function PatternOverridesBlockControls() {
89
- const { clientIds, hasPatternOverrides, hasParentPattern } = useSelect(
90
- (select) => {
91
- const {
92
- getBlockAttributes,
93
- getSelectedBlockClientIds,
94
- getBlockParentsByBlockName
95
- } = select(blockEditorStore);
96
- const selectedClientIds = getSelectedBlockClientIds();
97
- const _hasPatternOverrides = selectedClientIds.every(
98
- (clientId) => Object.values(
99
- getBlockAttributes(clientId)?.metadata?.bindings ?? {}
100
- ).some(
101
- (binding) => binding?.source === PATTERN_OVERRIDES_BINDING_SOURCE
102
- )
103
- );
104
- const _hasParentPattern = selectedClientIds.every(
105
- (clientId) => getBlockParentsByBlockName(clientId, "core/block", true).length > 0
106
- );
107
- return {
108
- clientIds: selectedClientIds,
109
- hasPatternOverrides: _hasPatternOverrides,
110
- hasParentPattern: _hasParentPattern
111
- };
112
- },
113
- []
114
- );
115
- return hasPatternOverrides && hasParentPattern ? /* @__PURE__ */ jsx(BlockControls, { group: "parent", children: /* @__PURE__ */ jsx(PatternOverridesToolbarIndicator, { clientIds }) }) : null;
116
- }
117
- export {
118
- PatternOverridesBlockControls as default
119
- };
120
- //# sourceMappingURL=pattern-overrides-block-controls.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/components/pattern-overrides-block-controls.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useId } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\tDropdownMenu,\n\tToolbarItem,\n\t__experimentalText as Text,\n} from '@wordpress/components';\nimport { store as blocksStore } from '@wordpress/blocks';\nimport { useSelect } from '@wordpress/data';\nimport { copy } from '@wordpress/icons';\nimport {\n\tstore as blockEditorStore,\n\tBlockIcon,\n\tprivateApis as blockEditorPrivateApis,\n\tBlockControls,\n} from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../lock-unlock';\nimport { PATTERN_OVERRIDES_BINDING_SOURCE } from '../constants';\n\nconst { useBlockDisplayTitle } = unlock( blockEditorPrivateApis );\n\nfunction PatternOverridesToolbarIndicator( { clientIds } ) {\n\tconst isSingleBlockSelected = clientIds.length === 1;\n\tconst { icon, firstBlockName } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlockAttributes, getBlockNamesByClientId } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst { getBlockType, getActiveBlockVariation } =\n\t\t\t\tselect( blocksStore );\n\t\t\tconst blockTypeNames = getBlockNamesByClientId( clientIds );\n\t\t\tconst _firstBlockTypeName = blockTypeNames[ 0 ];\n\t\t\tconst firstBlockType = getBlockType( _firstBlockTypeName );\n\t\t\tlet _icon;\n\t\t\tif ( isSingleBlockSelected ) {\n\t\t\t\tconst match = getActiveBlockVariation(\n\t\t\t\t\t_firstBlockTypeName,\n\t\t\t\t\tgetBlockAttributes( clientIds[ 0 ] )\n\t\t\t\t);\n\t\t\t\t// Take into account active block variations.\n\t\t\t\t_icon = match?.icon || firstBlockType.icon;\n\t\t\t} else {\n\t\t\t\tconst isSelectionOfSameType =\n\t\t\t\t\tnew Set( blockTypeNames ).size === 1;\n\t\t\t\t// When selection consists of blocks of multiple types, display an\n\t\t\t\t// appropriate icon to communicate the non-uniformity.\n\t\t\t\t_icon = isSelectionOfSameType ? firstBlockType.icon : copy;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\ticon: _icon,\n\t\t\t\tfirstBlockName: getBlockAttributes( clientIds[ 0 ] ).metadata\n\t\t\t\t\t.name,\n\t\t\t};\n\t\t},\n\t\t[ clientIds, isSingleBlockSelected ]\n\t);\n\tconst firstBlockTitle = useBlockDisplayTitle( {\n\t\tclientId: clientIds[ 0 ],\n\t\tmaximumLength: 35,\n\t} );\n\n\tconst blockDescription = isSingleBlockSelected\n\t\t? sprintf(\n\t\t\t\t/* translators: 1: The block type's name. 2: The block's user-provided name (the same as the override name). */\n\t\t\t\t__( 'This %1$s is editable using the \"%2$s\" override.' ),\n\t\t\t\tfirstBlockTitle.toLowerCase(),\n\t\t\t\tfirstBlockName\n\t\t )\n\t\t: __( 'These blocks are editable using overrides.' );\n\n\tconst descriptionId = useId();\n\n\treturn (\n\t\t<ToolbarItem>\n\t\t\t{ ( toggleProps ) => (\n\t\t\t\t<DropdownMenu\n\t\t\t\t\tclassName=\"patterns-pattern-overrides-toolbar-indicator\"\n\t\t\t\t\tlabel={ firstBlockTitle }\n\t\t\t\t\tpopoverProps={ {\n\t\t\t\t\t\tplacement: 'bottom-start',\n\t\t\t\t\t\tclassName:\n\t\t\t\t\t\t\t'patterns-pattern-overrides-toolbar-indicator__popover',\n\t\t\t\t\t} }\n\t\t\t\t\ticon={\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<BlockIcon\n\t\t\t\t\t\t\t\ticon={ icon }\n\t\t\t\t\t\t\t\tclassName=\"patterns-pattern-overrides-toolbar-indicator-icon\"\n\t\t\t\t\t\t\t\tshowColors\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\ttoggleProps={ {\n\t\t\t\t\t\tdescription: blockDescription,\n\t\t\t\t\t\t...toggleProps,\n\t\t\t\t\t} }\n\t\t\t\t\tmenuProps={ {\n\t\t\t\t\t\torientation: 'both',\n\t\t\t\t\t\t'aria-describedby': descriptionId,\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t{ () => (\n\t\t\t\t\t\t<Text id={ descriptionId }>{ blockDescription }</Text>\n\t\t\t\t\t) }\n\t\t\t\t</DropdownMenu>\n\t\t\t) }\n\t\t</ToolbarItem>\n\t);\n}\n\nexport default function PatternOverridesBlockControls() {\n\tconst { clientIds, hasPatternOverrides, hasParentPattern } = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlockAttributes,\n\t\t\t\tgetSelectedBlockClientIds,\n\t\t\t\tgetBlockParentsByBlockName,\n\t\t\t} = select( blockEditorStore );\n\t\t\tconst selectedClientIds = getSelectedBlockClientIds();\n\t\t\tconst _hasPatternOverrides = selectedClientIds.every(\n\t\t\t\t( clientId ) =>\n\t\t\t\t\tObject.values(\n\t\t\t\t\t\tgetBlockAttributes( clientId )?.metadata?.bindings ?? {}\n\t\t\t\t\t).some(\n\t\t\t\t\t\t( binding ) =>\n\t\t\t\t\t\t\tbinding?.source === PATTERN_OVERRIDES_BINDING_SOURCE\n\t\t\t\t\t)\n\t\t\t);\n\t\t\tconst _hasParentPattern = selectedClientIds.every(\n\t\t\t\t( clientId ) =>\n\t\t\t\t\tgetBlockParentsByBlockName( clientId, 'core/block', true )\n\t\t\t\t\t\t.length > 0\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tclientIds: selectedClientIds,\n\t\t\t\thasPatternOverrides: _hasPatternOverrides,\n\t\t\t\thasParentPattern: _hasParentPattern,\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\n\treturn hasPatternOverrides && hasParentPattern ? (\n\t\t<BlockControls group=\"parent\">\n\t\t\t<PatternOverridesToolbarIndicator clientIds={ clientIds } />\n\t\t</BlockControls>\n\t) : null;\n}\n"],
5
- "mappings": "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",
6
- "names": []
7
- }
@@ -1,155 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { useId } from '@wordpress/element';
5
- import { __, sprintf } from '@wordpress/i18n';
6
- import {
7
- DropdownMenu,
8
- ToolbarItem,
9
- __experimentalText as Text,
10
- } from '@wordpress/components';
11
- import { store as blocksStore } from '@wordpress/blocks';
12
- import { useSelect } from '@wordpress/data';
13
- import { copy } from '@wordpress/icons';
14
- import {
15
- store as blockEditorStore,
16
- BlockIcon,
17
- privateApis as blockEditorPrivateApis,
18
- BlockControls,
19
- } from '@wordpress/block-editor';
20
-
21
- /**
22
- * Internal dependencies
23
- */
24
- import { unlock } from '../lock-unlock';
25
- import { PATTERN_OVERRIDES_BINDING_SOURCE } from '../constants';
26
-
27
- const { useBlockDisplayTitle } = unlock( blockEditorPrivateApis );
28
-
29
- function PatternOverridesToolbarIndicator( { clientIds } ) {
30
- const isSingleBlockSelected = clientIds.length === 1;
31
- const { icon, firstBlockName } = useSelect(
32
- ( select ) => {
33
- const { getBlockAttributes, getBlockNamesByClientId } =
34
- select( blockEditorStore );
35
- const { getBlockType, getActiveBlockVariation } =
36
- select( blocksStore );
37
- const blockTypeNames = getBlockNamesByClientId( clientIds );
38
- const _firstBlockTypeName = blockTypeNames[ 0 ];
39
- const firstBlockType = getBlockType( _firstBlockTypeName );
40
- let _icon;
41
- if ( isSingleBlockSelected ) {
42
- const match = getActiveBlockVariation(
43
- _firstBlockTypeName,
44
- getBlockAttributes( clientIds[ 0 ] )
45
- );
46
- // Take into account active block variations.
47
- _icon = match?.icon || firstBlockType.icon;
48
- } else {
49
- const isSelectionOfSameType =
50
- new Set( blockTypeNames ).size === 1;
51
- // When selection consists of blocks of multiple types, display an
52
- // appropriate icon to communicate the non-uniformity.
53
- _icon = isSelectionOfSameType ? firstBlockType.icon : copy;
54
- }
55
-
56
- return {
57
- icon: _icon,
58
- firstBlockName: getBlockAttributes( clientIds[ 0 ] ).metadata
59
- .name,
60
- };
61
- },
62
- [ clientIds, isSingleBlockSelected ]
63
- );
64
- const firstBlockTitle = useBlockDisplayTitle( {
65
- clientId: clientIds[ 0 ],
66
- maximumLength: 35,
67
- } );
68
-
69
- const blockDescription = isSingleBlockSelected
70
- ? sprintf(
71
- /* translators: 1: The block type's name. 2: The block's user-provided name (the same as the override name). */
72
- __( 'This %1$s is editable using the "%2$s" override.' ),
73
- firstBlockTitle.toLowerCase(),
74
- firstBlockName
75
- )
76
- : __( 'These blocks are editable using overrides.' );
77
-
78
- const descriptionId = useId();
79
-
80
- return (
81
- <ToolbarItem>
82
- { ( toggleProps ) => (
83
- <DropdownMenu
84
- className="patterns-pattern-overrides-toolbar-indicator"
85
- label={ firstBlockTitle }
86
- popoverProps={ {
87
- placement: 'bottom-start',
88
- className:
89
- 'patterns-pattern-overrides-toolbar-indicator__popover',
90
- } }
91
- icon={
92
- <>
93
- <BlockIcon
94
- icon={ icon }
95
- className="patterns-pattern-overrides-toolbar-indicator-icon"
96
- showColors
97
- />
98
- </>
99
- }
100
- toggleProps={ {
101
- description: blockDescription,
102
- ...toggleProps,
103
- } }
104
- menuProps={ {
105
- orientation: 'both',
106
- 'aria-describedby': descriptionId,
107
- } }
108
- >
109
- { () => (
110
- <Text id={ descriptionId }>{ blockDescription }</Text>
111
- ) }
112
- </DropdownMenu>
113
- ) }
114
- </ToolbarItem>
115
- );
116
- }
117
-
118
- export default function PatternOverridesBlockControls() {
119
- const { clientIds, hasPatternOverrides, hasParentPattern } = useSelect(
120
- ( select ) => {
121
- const {
122
- getBlockAttributes,
123
- getSelectedBlockClientIds,
124
- getBlockParentsByBlockName,
125
- } = select( blockEditorStore );
126
- const selectedClientIds = getSelectedBlockClientIds();
127
- const _hasPatternOverrides = selectedClientIds.every(
128
- ( clientId ) =>
129
- Object.values(
130
- getBlockAttributes( clientId )?.metadata?.bindings ?? {}
131
- ).some(
132
- ( binding ) =>
133
- binding?.source === PATTERN_OVERRIDES_BINDING_SOURCE
134
- )
135
- );
136
- const _hasParentPattern = selectedClientIds.every(
137
- ( clientId ) =>
138
- getBlockParentsByBlockName( clientId, 'core/block', true )
139
- .length > 0
140
- );
141
- return {
142
- clientIds: selectedClientIds,
143
- hasPatternOverrides: _hasPatternOverrides,
144
- hasParentPattern: _hasParentPattern,
145
- };
146
- },
147
- []
148
- );
149
-
150
- return hasPatternOverrides && hasParentPattern ? (
151
- <BlockControls group="parent">
152
- <PatternOverridesToolbarIndicator clientIds={ clientIds } />
153
- </BlockControls>
154
- ) : null;
155
- }