@secretstache/wordpress-gutenberg 0.3.11 → 0.3.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@secretstache/wordpress-gutenberg",
3
- "version": "0.3.11",
3
+ "version": "0.3.13",
4
4
  "description": "",
5
5
  "author": "Secret Stache",
6
6
  "license": "GPL-2.0-or-later",
@@ -1,4 +1,4 @@
1
- import { useState } from '@wordpress/element';
1
+ import { useMemo } from '@wordpress/element';
2
2
  import { SelectControl } from '@wordpress/components';
3
3
 
4
4
  import { MediaControl } from './MediaControl.js';
@@ -8,26 +8,26 @@ export const MediaTypeControl = (props) => {
8
8
  const {
9
9
  types = [ MEDIA_TYPES.IMAGE, MEDIA_TYPES.VIDEO ],
10
10
 
11
- selectedType = MEDIA_TYPES.IMAGE,
12
- typeOnSelect,
11
+ selectedType,
12
+ onTypeChange,
13
13
 
14
14
  mediaId,
15
15
  mediaUrl,
16
16
  mediaFileName = '',
17
17
 
18
- mediaOnSelect,
19
- mediaOnRemove,
18
+ onMediaSelect,
19
+ onMediaRemove,
20
20
 
21
21
  label = 'Media Type',
22
22
  } = props;
23
23
 
24
-
25
- const typesOptions = types
24
+ const typesOptions = useMemo(() => types
26
25
  ?.filter((type) => MEDIA_TYPE_LABELS[type]) // Ensure it's an allowed type
27
26
  ?.map((type) => ({
28
27
  label: MEDIA_TYPE_LABELS[type],
29
28
  value: type,
30
- }));
29
+ }))
30
+ , [ types ]);
31
31
 
32
32
  return (
33
33
  <>
@@ -36,7 +36,7 @@ export const MediaTypeControl = (props) => {
36
36
  <SelectControl
37
37
  label={label}
38
38
  value={selectedType}
39
- onChange={(type) => typeOnSelect(type)}
39
+ onChange={onTypeChange}
40
40
  options={typesOptions}
41
41
  />
42
42
  )
@@ -49,8 +49,8 @@ export const MediaTypeControl = (props) => {
49
49
  mediaUrl={mediaUrl}
50
50
  mediaFileName={mediaFileName}
51
51
  type={selectedType}
52
- onSelect={mediaOnSelect}
53
- onRemove={mediaOnRemove}
52
+ onSelect={onMediaSelect}
53
+ onRemove={onMediaRemove}
54
54
  />
55
55
  )
56
56
  }
@@ -18,8 +18,7 @@ export const useAccordionItem = (itemId, activeItemId, setActiveItemId, contentS
18
18
  }
19
19
  };
20
20
 
21
- // TODO: rename to toggleItem
22
- const toggleContent = () => {
21
+ const toggleItem = () => {
23
22
  setActiveItemId(isActive ? null : itemId);
24
23
  };
25
24
 
@@ -29,7 +28,7 @@ export const useAccordionItem = (itemId, activeItemId, setActiveItemId, contentS
29
28
  } else {
30
29
  closeContent();
31
30
  }
32
- }, [isActive]);
31
+ }, [ isActive ]);
33
32
 
34
33
  useEffect(() => {
35
34
  if (!isActive || !blockRef.current) return;
@@ -45,7 +44,13 @@ export const useAccordionItem = (itemId, activeItemId, setActiveItemId, contentS
45
44
  resizeObserver.observe(blockRef.current);
46
45
 
47
46
  return () => resizeObserver.disconnect();
48
- }, [isActive]);
49
-
50
- return { blockRef, toggleContent, isActive };
47
+ }, [ isActive ]);
48
+
49
+ return {
50
+ blockRef,
51
+ toggleItem,
52
+ openContent,
53
+ closeContent,
54
+ isActive,
55
+ };
51
56
  };
@@ -13,17 +13,19 @@ export const linkControlAttribute = {
13
13
  },
14
14
  };
15
15
 
16
- export const mediaAttribute = {
17
- media: {
16
+ export const getMediaAttribute = (name = 'media') => ({
17
+ [`${name}`]: {
18
18
  type: 'object',
19
19
  default: {
20
20
  id: null,
21
- url: '',
22
- alt: '',
23
- filename: '',
21
+ url: null,
22
+ alt: null,
23
+ name: null,
24
+ filename: null,
25
+ mime: null,
24
26
  },
25
27
  },
26
- };
28
+ });
27
29
 
28
30
  export const contentAttribute = {
29
31
  title: {
@@ -36,22 +38,13 @@ export const contentAttribute = {
36
38
  },
37
39
  };
38
40
 
39
- export const animationAttribute = {
40
- animationFile: {
41
- type: 'object',
42
- default: {
43
- id: null,
44
- url: null,
45
- name: null,
46
- filename: null,
47
- mime: null,
48
- },
49
- },
41
+ export const getAnimationAttribute = (name = 'animationFile') => ({
42
+ ...getMediaAttribute(name),
50
43
  isAnimationLooped: {
51
44
  type: 'boolean',
52
45
  default: true,
53
46
  },
54
- };
47
+ });
55
48
 
56
49
  export const curatedPostsAttribute = {
57
50
  curatedPosts: {
@@ -137,50 +130,39 @@ export const getDataQueryAttributes = (
137
130
  * for background color, media, and overlays based on the provided configurations.
138
131
  *
139
132
  * @param {Object} [options={}] - The options for generating background attributes.
140
- * @param {Object} [options.defaultBackgroundColor={ value: '', slug: '' }] - The default background color attribute.
141
133
  * @param {boolean} [options.hasBackgroundMedia=false] - Flag to determine if background media attributes should be included.
142
- * @param {string} [options.defaultBackgroundMediaType=''] - The default type of background media if media attributes are included.
134
+ * @param {string} [options.mediaAttributeName='media'] - Background media attribute name.
143
135
  * @param {boolean} [options.hasOverlay=false] - Flag to determine if overlay attributes should be included.
144
- * @param {Object} [options.defaultOverlayColor={ value: '', slug: '' }] - The default overlay color attribute if overlay attributes are included.
145
136
  *
146
137
  * @returns {Object} An object containing the attributes for the block's background configuration.
147
138
  */
148
139
  export const getBaseBackgroundAttributes = ({
149
- defaultBackgroundColor = { value: '', slug: '' },
150
-
151
140
  hasBackgroundMedia = false,
152
- defaultBackgroundMediaType = '',
153
-
141
+ mediaAttributeName = 'media',
154
142
  hasOverlay = false,
155
- defaultOverlayColor = { value: '', slug: '' },
156
143
  } = {}) => {
157
144
  const backgroundMediaAttribute = {
158
145
  isIncludeBackgroundMedia: {
159
146
  type: 'boolean',
160
- default: false,
161
147
  },
162
148
  backgroundMediaType: {
163
149
  type: 'string',
164
- default: defaultBackgroundMediaType,
165
150
  },
166
- ...mediaAttribute,
151
+ ...getMediaAttribute(mediaAttributeName),
167
152
  };
168
153
 
169
154
  const overlayAttribute = {
170
155
  isIncludeOverlay: {
171
156
  type: 'boolean',
172
- default: false,
173
157
  },
174
158
  overlayColor: {
175
159
  type: 'object',
176
- default: defaultOverlayColor,
177
160
  },
178
161
  };
179
162
 
180
163
  return {
181
164
  backgroundColor: {
182
165
  type: 'object',
183
- default: defaultBackgroundColor,
184
166
  },
185
167
 
186
168
  ...(hasBackgroundMedia ? backgroundMediaAttribute : {}),