@secretstache/wordpress-gutenberg 0.3.10 → 0.3.12

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.10",
3
+ "version": "0.3.12",
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: {
@@ -132,55 +125,54 @@ export const getDataQueryAttributes = (
132
125
  ...(hasNumberOfPosts ? numberOfPostsAttribute : {}),
133
126
  };
134
127
  };
135
-
136
128
  /**
137
- * Returns the base background attribute object with configurable default background color and media type.
129
+ * Generates a set of attributes for background settings in a block, including options
130
+ * for background color, media, and overlays based on the provided configurations.
131
+ *
132
+ * @param {Object} [options={}] - The options for generating background attributes.
133
+ * @param {boolean} [options.hasBackgroundMedia=false] - Flag to determine if background media attributes should be included.
134
+ * @param {string} [options.mediaAttributeName='media'] - Background media attribute name.
135
+ * @param {boolean} [options.hasOverlay=false] - Flag to determine if overlay attributes should be included.
138
136
  *
139
- * @param {Object} options - The options for configuring the background attributes.
140
- * @param {string} [options.defaultBackgroundMediaType=''] - The default background media type.
141
- * @param {Object} options.defaultBackgroundColor - The background color configuration.
142
- * @param {string} options.defaultBackgroundColor.value - The hex value of the background color.
143
- * @param {string} options.defaultBackgroundColor.slug - The slug of the background color.
144
- * @param {boolean} [options.hasIncludeBackgroundMediaAttribute=false] - Whether to include the background media attribute.
145
- * @param {boolean} [options.hasIncludeOverlayAttribute=false] - Whether to include the overlay attribute.
146
- * @returns {Object} The base background attribute object.
137
+ * @returns {Object} An object containing the attributes for the block's background configuration.
147
138
  */
148
139
  export const getBaseBackgroundAttributes = ({
149
- defaultBackgroundMediaType = '',
150
- defaultBackgroundColor = { value: '', slug: '' },
151
- hasIncludeBackgroundMediaAttribute = false,
152
- hasIncludeOverlayAttribute = false,
140
+ hasBackgroundMedia = false,
141
+ mediaAttributeName = 'media',
142
+ hasOverlay = false,
153
143
  } = {}) => {
154
- // TODO: add the overlay color attribute
155
- const isIncludeOverlayAttribute = {
156
- isIncludeOverlay: {
144
+ const backgroundMediaAttribute = {
145
+ isIncludeBackgroundMedia: {
157
146
  type: 'boolean',
158
- default: false,
159
- }
147
+ default: null,
148
+ },
149
+ backgroundMediaType: {
150
+ type: 'string',
151
+ default: null,
152
+ },
153
+ ...getMediaAttribute(mediaAttributeName),
160
154
  };
161
155
 
162
- const isIncludeBackgroundMediaAttribute = {
163
- isIncludeBackgroundMedia: {
156
+ const overlayAttribute = {
157
+ isIncludeOverlay: {
164
158
  type: 'boolean',
165
- default: false,
166
- }
159
+ default: null,
160
+ },
161
+ overlayColor: {
162
+ type: 'object',
163
+ default: null,
164
+ },
167
165
  };
168
166
 
169
167
  return {
170
- ...(hasIncludeBackgroundMediaAttribute ? isIncludeBackgroundMediaAttribute : {}),
171
-
172
- backgroundMediaType: {
173
- type: 'string',
174
- default: defaultBackgroundMediaType,
175
- },
176
168
  backgroundColor: {
177
169
  type: 'object',
178
- default: defaultBackgroundColor,
170
+ default: null,
179
171
  },
180
172
 
181
- ...mediaAttribute,
173
+ ...(hasBackgroundMedia ? backgroundMediaAttribute : {}),
182
174
 
183
- ...(hasIncludeOverlayAttribute ? isIncludeOverlayAttribute : {}),
175
+ ...(hasOverlay ? overlayAttribute : {}),
184
176
  };
185
177
  };
186
178