@wordpress/reusable-blocks 4.16.0 → 4.17.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 (47) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/index.js +0 -2
  3. package/build/components/index.js.map +1 -1
  4. package/build/components/reusable-blocks-menu-items/index.js +11 -15
  5. package/build/components/reusable-blocks-menu-items/index.js.map +1 -1
  6. package/build/components/reusable-blocks-menu-items/index.native.js +0 -2
  7. package/build/components/reusable-blocks-menu-items/index.native.js.map +1 -1
  8. package/build/components/reusable-blocks-menu-items/reusable-block-convert-button.js +21 -30
  9. package/build/components/reusable-blocks-menu-items/reusable-block-convert-button.js.map +1 -1
  10. package/build/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js +2 -16
  11. package/build/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js.map +1 -1
  12. package/build/index.js +0 -3
  13. package/build/index.js.map +1 -1
  14. package/build/index.native.js +0 -4
  15. package/build/index.native.js.map +1 -1
  16. package/build/lock-unlock.js +1 -2
  17. package/build/lock-unlock.js.map +1 -1
  18. package/build/store/actions.js +9 -21
  19. package/build/store/actions.js.map +1 -1
  20. package/build/store/index.js +2 -9
  21. package/build/store/index.js.map +1 -1
  22. package/build/store/reducer.js +3 -6
  23. package/build/store/reducer.js.map +1 -1
  24. package/build/store/selectors.js +0 -1
  25. package/build/store/selectors.js.map +1 -1
  26. package/build-module/components/index.js.map +1 -1
  27. package/build-module/components/reusable-blocks-menu-items/index.js +12 -11
  28. package/build-module/components/reusable-blocks-menu-items/index.js.map +1 -1
  29. package/build-module/components/reusable-blocks-menu-items/index.native.js.map +1 -1
  30. package/build-module/components/reusable-blocks-menu-items/reusable-block-convert-button.js +24 -22
  31. package/build-module/components/reusable-blocks-menu-items/reusable-block-convert-button.js.map +1 -1
  32. package/build-module/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js +4 -11
  33. package/build-module/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js.map +1 -1
  34. package/build-module/index.js.map +1 -1
  35. package/build-module/index.native.js.map +1 -1
  36. package/build-module/lock-unlock.js.map +1 -1
  37. package/build-module/store/actions.js +10 -12
  38. package/build-module/store/actions.js.map +1 -1
  39. package/build-module/store/index.js +2 -2
  40. package/build-module/store/index.js.map +1 -1
  41. package/build-module/store/reducer.js +2 -2
  42. package/build-module/store/reducer.js.map +1 -1
  43. package/build-module/store/selectors.js.map +1 -1
  44. package/package.json +14 -13
  45. package/src/components/reusable-blocks-menu-items/index.js +16 -15
  46. package/src/components/reusable-blocks-menu-items/reusable-block-convert-button.js +64 -72
  47. package/src/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js +3 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/reusable-blocks",
3
- "version": "4.16.0",
3
+ "version": "4.17.0",
4
4
  "description": "Reusable blocks utilities.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -28,17 +28,18 @@
28
28
  "{src,build,build-module}/{index.js,store/index.js}"
29
29
  ],
30
30
  "dependencies": {
31
- "@wordpress/block-editor": "^12.7.0",
32
- "@wordpress/blocks": "^12.16.0",
33
- "@wordpress/components": "^25.5.0",
34
- "@wordpress/core-data": "^6.16.0",
35
- "@wordpress/data": "^9.9.0",
36
- "@wordpress/element": "^5.16.0",
37
- "@wordpress/i18n": "^4.39.0",
38
- "@wordpress/icons": "^9.30.0",
39
- "@wordpress/notices": "^4.7.0",
40
- "@wordpress/private-apis": "^0.21.0",
41
- "@wordpress/url": "^3.40.0"
31
+ "@babel/runtime": "^7.16.0",
32
+ "@wordpress/block-editor": "^12.8.0",
33
+ "@wordpress/blocks": "^12.17.0",
34
+ "@wordpress/components": "^25.6.0",
35
+ "@wordpress/core-data": "^6.17.0",
36
+ "@wordpress/data": "^9.10.0",
37
+ "@wordpress/element": "^5.17.0",
38
+ "@wordpress/i18n": "^4.40.0",
39
+ "@wordpress/icons": "^9.31.0",
40
+ "@wordpress/notices": "^4.8.0",
41
+ "@wordpress/private-apis": "^0.22.0",
42
+ "@wordpress/url": "^3.41.0"
42
43
  },
43
44
  "peerDependencies": {
44
45
  "react": "^18.0.0",
@@ -47,5 +48,5 @@
47
48
  "publishConfig": {
48
49
  "access": "public"
49
50
  },
50
- "gitHead": "b898cf1dc8e70841d1647ea0994ac6278acc18a7"
51
+ "gitHead": "78a288d55b83a713b2f7d98d5a855c0771a2afc6"
51
52
  }
@@ -1,8 +1,7 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { useSelect } from '@wordpress/data';
5
- import { store as blockEditorStore } from '@wordpress/block-editor';
4
+ import { BlockSettingsMenuControls } from '@wordpress/block-editor';
6
5
 
7
6
  /**
8
7
  * Internal dependencies
@@ -11,20 +10,22 @@ import ReusableBlockConvertButton from './reusable-block-convert-button';
11
10
  import ReusableBlocksManageButton from './reusable-blocks-manage-button';
12
11
 
13
12
  export default function ReusableBlocksMenuItems( { rootClientId } ) {
14
- const clientIds = useSelect(
15
- ( select ) => select( blockEditorStore ).getSelectedBlockClientIds(),
16
- []
17
- );
18
-
19
13
  return (
20
- <>
21
- <ReusableBlockConvertButton
22
- clientIds={ clientIds }
23
- rootClientId={ rootClientId }
24
- />
25
- { clientIds.length === 1 && (
26
- <ReusableBlocksManageButton clientId={ clientIds[ 0 ] } />
14
+ <BlockSettingsMenuControls>
15
+ { ( { onClose, selectedClientIds } ) => (
16
+ <>
17
+ <ReusableBlockConvertButton
18
+ clientIds={ selectedClientIds }
19
+ rootClientId={ rootClientId }
20
+ onClose={ onClose }
21
+ />
22
+ { selectedClientIds.length === 1 && (
23
+ <ReusableBlocksManageButton
24
+ clientId={ selectedClientIds[ 0 ] }
25
+ />
26
+ ) }
27
+ </>
27
28
  ) }
28
- </>
29
+ </BlockSettingsMenuControls>
29
30
  );
30
31
  }
@@ -3,7 +3,6 @@
3
3
  */
4
4
  import { hasBlockSupport, isReusableBlock } from '@wordpress/blocks';
5
5
  import {
6
- BlockSettingsMenuControls,
7
6
  store as blockEditorStore,
8
7
  privateApis as blockEditorPrivateApis,
9
8
  } from '@wordpress/block-editor';
@@ -35,11 +34,13 @@ import { unlock } from '../../lock-unlock';
35
34
  * @param {Object} props Component props.
36
35
  * @param {string[]} props.clientIds Client ids of selected blocks.
37
36
  * @param {string} props.rootClientId ID of the currently selected top-level block.
37
+ * @param {()=>void} props.onClose Callback to close the menu.
38
38
  * @return {import('@wordpress/element').WPComponent} The menu control or null.
39
39
  */
40
40
  export default function ReusableBlockConvertButton( {
41
41
  clientIds,
42
42
  rootClientId,
43
+ onClose,
43
44
  } ) {
44
45
  const { useReusableBlocksRenameHint, ReusableBlocksRenameHint } = unlock(
45
46
  blockEditorPrivateApis
@@ -148,80 +149,71 @@ export default function ReusableBlockConvertButton( {
148
149
  }
149
150
 
150
151
  return (
151
- <BlockSettingsMenuControls>
152
- { ( { onClose } ) => (
153
- <>
154
- <MenuItem
155
- icon={ symbol }
156
- onClick={ () => setIsModalOpen( true ) }
152
+ <>
153
+ <MenuItem icon={ symbol } onClick={ () => setIsModalOpen( true ) }>
154
+ { showRenameHint
155
+ ? __( 'Create pattern/reusable block' )
156
+ : __( 'Create pattern' ) }
157
+ </MenuItem>
158
+ { isModalOpen && (
159
+ <Modal
160
+ title={ __( 'Create pattern' ) }
161
+ onRequestClose={ () => {
162
+ setIsModalOpen( false );
163
+ setTitle( '' );
164
+ } }
165
+ overlayClassName="reusable-blocks-menu-items__convert-modal"
166
+ >
167
+ <form
168
+ onSubmit={ ( event ) => {
169
+ event.preventDefault();
170
+ onConvert( title );
171
+ setIsModalOpen( false );
172
+ setTitle( '' );
173
+ onClose();
174
+ } }
157
175
  >
158
- { showRenameHint
159
- ? __( 'Create pattern/reusable block' )
160
- : __( 'Create pattern' ) }
161
- </MenuItem>
162
- { isModalOpen && (
163
- <Modal
164
- title={ __( 'Create pattern' ) }
165
- onRequestClose={ () => {
166
- setIsModalOpen( false );
167
- setTitle( '' );
168
- } }
169
- overlayClassName="reusable-blocks-menu-items__convert-modal"
170
- >
171
- <form
172
- onSubmit={ ( event ) => {
173
- event.preventDefault();
174
- onConvert( title );
175
- setIsModalOpen( false );
176
- setTitle( '' );
177
- onClose();
178
- } }
179
- >
180
- <VStack spacing="5">
181
- <ReusableBlocksRenameHint />
182
- <TextControl
183
- __nextHasNoMarginBottom
184
- label={ __( 'Name' ) }
185
- value={ title }
186
- onChange={ setTitle }
187
- placeholder={ __( 'My pattern' ) }
188
- />
176
+ <VStack spacing="5">
177
+ <ReusableBlocksRenameHint />
178
+ <TextControl
179
+ __nextHasNoMarginBottom
180
+ label={ __( 'Name' ) }
181
+ value={ title }
182
+ onChange={ setTitle }
183
+ placeholder={ __( 'My pattern' ) }
184
+ />
189
185
 
190
- <ToggleControl
191
- label={ __( 'Synced' ) }
192
- help={ __(
193
- 'Editing the pattern will update it anywhere it is used.'
194
- ) }
195
- checked={ ! syncType }
196
- onChange={ () => {
197
- setSyncType(
198
- ! syncType
199
- ? 'unsynced'
200
- : undefined
201
- );
202
- } }
203
- />
204
- <HStack justify="right">
205
- <Button
206
- variant="tertiary"
207
- onClick={ () => {
208
- setIsModalOpen( false );
209
- setTitle( '' );
210
- } }
211
- >
212
- { __( 'Cancel' ) }
213
- </Button>
186
+ <ToggleControl
187
+ label={ __( 'Synced' ) }
188
+ help={ __(
189
+ 'Editing the pattern will update it anywhere it is used.'
190
+ ) }
191
+ checked={ ! syncType }
192
+ onChange={ () => {
193
+ setSyncType(
194
+ ! syncType ? 'unsynced' : undefined
195
+ );
196
+ } }
197
+ />
198
+ <HStack justify="right">
199
+ <Button
200
+ variant="tertiary"
201
+ onClick={ () => {
202
+ setIsModalOpen( false );
203
+ setTitle( '' );
204
+ } }
205
+ >
206
+ { __( 'Cancel' ) }
207
+ </Button>
214
208
 
215
- <Button variant="primary" type="submit">
216
- { __( 'Create' ) }
217
- </Button>
218
- </HStack>
219
- </VStack>
220
- </form>
221
- </Modal>
222
- ) }
223
- </>
209
+ <Button variant="primary" type="submit">
210
+ { __( 'Create' ) }
211
+ </Button>
212
+ </HStack>
213
+ </VStack>
214
+ </form>
215
+ </Modal>
224
216
  ) }
225
- </BlockSettingsMenuControls>
217
+ </>
226
218
  );
227
219
  }
@@ -5,10 +5,7 @@ import { MenuItem } from '@wordpress/components';
5
5
  import { __ } from '@wordpress/i18n';
6
6
  import { isReusableBlock } from '@wordpress/blocks';
7
7
  import { useSelect, useDispatch } from '@wordpress/data';
8
- import {
9
- BlockSettingsMenuControls,
10
- store as blockEditorStore,
11
- } from '@wordpress/block-editor';
8
+ import { store as blockEditorStore } from '@wordpress/block-editor';
12
9
  import { addQueryArgs } from '@wordpress/url';
13
10
  import { store as coreStore } from '@wordpress/core-data';
14
11
 
@@ -62,7 +59,7 @@ function ReusableBlocksManageButton( { clientId } ) {
62
59
  }
63
60
 
64
61
  return (
65
- <BlockSettingsMenuControls>
62
+ <>
66
63
  <MenuItem href={ managePatternsUrl }>
67
64
  { __( 'Manage patterns' ) }
68
65
  </MenuItem>
@@ -73,7 +70,7 @@ function ReusableBlocksManageButton( { clientId } ) {
73
70
  : __( 'Detach pattern' ) }
74
71
  </MenuItem>
75
72
  ) }
76
- </BlockSettingsMenuControls>
73
+ </>
77
74
  );
78
75
  }
79
76