@secretstache/wordpress-gutenberg 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@secretstache/wordpress-gutenberg",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "",
5
5
  "author": "Secret Stache",
6
6
  "license": "GPL-2.0-or-later",
@@ -2,22 +2,27 @@ import { useState } from '@wordpress/element';
2
2
  import { SelectControl } from '@wordpress/components';
3
3
 
4
4
  import { MediaControl } from './MediaControl.js';
5
- import { MEDIA_TYPE_LABELS } from '../utils/index.js';
5
+ import { MEDIA_TYPE_LABELS, MEDIA_TYPES } from '../utils/index.js';
6
6
 
7
7
  export const MediaTypeControl = (props) => {
8
8
  const {
9
- mediaTypes = [],
9
+ types = [ MEDIA_TYPES.IMAGE, MEDIA_TYPES.VIDEO ],
10
+
11
+ selectedType = MEDIA_TYPES.IMAGE,
12
+ typeOnSelect,
13
+
10
14
  mediaId,
11
15
  mediaUrl,
12
16
  mediaFileName = '',
17
+
13
18
  mediaOnSelect,
14
19
  mediaOnRemove,
20
+
15
21
  label = 'Media Type',
16
22
  } = props;
17
23
 
18
- const [selectedMediaType, setSelectedMediaType] = useState(mediaTypes?.[0]);
19
24
 
20
- const mediaTypesOptions = mediaTypes
25
+ const typesOptions = types
21
26
  ?.filter((type) => MEDIA_TYPE_LABELS[type]) // Ensure it's an allowed type
22
27
  ?.map((type) => ({
23
28
  label: MEDIA_TYPE_LABELS[type],
@@ -27,23 +32,23 @@ export const MediaTypeControl = (props) => {
27
32
  return (
28
33
  <>
29
34
  {
30
- mediaTypes && (
35
+ types && (
31
36
  <SelectControl
32
37
  label={label}
33
- value={selectedMediaType}
34
- onChange={(mediaType) => setSelectedMediaType(mediaType)}
35
- options={mediaTypesOptions}
38
+ value={selectedType}
39
+ onChange={(type) => typeOnSelect(type)}
40
+ options={typesOptions}
36
41
  />
37
42
  )
38
43
  }
39
44
 
40
45
  {
41
- selectedMediaType && (
46
+ selectedType && (
42
47
  <MediaControl
43
48
  mediaId={mediaId}
44
49
  mediaUrl={mediaUrl}
45
50
  mediaFileName={mediaFileName}
46
- type={selectedMediaType}
51
+ type={selectedType}
47
52
  onSelect={mediaOnSelect}
48
53
  onRemove={mediaOnRemove}
49
54
  />
@@ -9,3 +9,4 @@ export { useAccordionItem } from './useAccordionItem.js';
9
9
  export { useBlockTabsData } from './useBlockTabsData.js';
10
10
  export { useAllowedBlocks } from './useAllowedBlocks.js';
11
11
  export { useChildBlockPosition } from './useChildBlockPosition.js';
12
+ export { useFilterBlocks } from './useFilterBlocks.js';
@@ -0,0 +1,15 @@
1
+ import { useSelect } from '@wordpress/data';
2
+ import { useMemo } from '@wordpress/element';
3
+
4
+ export const useFilterBlocks = (filter) => {
5
+ const allBlocks = useSelect(
6
+ (select) => select('core/blocks').getBlockTypes(),
7
+ [],
8
+ );
9
+
10
+ return useMemo(() => allBlocks
11
+ ?.filter((block) => filter(block))
12
+ ?.map((block) => block.name),
13
+ [ allBlocks, filter ],
14
+ );
15
+ };
@@ -152,7 +152,7 @@ export const getBaseBackgroundAttributes = (
152
152
  },
153
153
  backgroundMediaType: {
154
154
  type: 'string',
155
- default: '',
155
+ default: defaultBackgroundMediaType,
156
156
  },
157
157
  backgroundColor: {
158
158
  type: 'object',