@secretstache/wordpress-gutenberg 0.3.10 → 0.3.12
Sign up to get free protection for your applications and to get access to all the features.
- package/build/index.js +3 -3
- package/build/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/MediaTypeControl.js +11 -11
- package/src/hooks/useAccordionItem.js +11 -6
- package/src/utils/attributes.js +42 -50
package/package.json
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
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
|
12
|
-
|
11
|
+
selectedType,
|
12
|
+
onTypeChange,
|
13
13
|
|
14
14
|
mediaId,
|
15
15
|
mediaUrl,
|
16
16
|
mediaFileName = '',
|
17
17
|
|
18
|
-
|
19
|
-
|
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={
|
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={
|
53
|
-
onRemove={
|
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
|
-
|
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 {
|
47
|
+
}, [ isActive ]);
|
48
|
+
|
49
|
+
return {
|
50
|
+
blockRef,
|
51
|
+
toggleItem,
|
52
|
+
openContent,
|
53
|
+
closeContent,
|
54
|
+
isActive,
|
55
|
+
};
|
51
56
|
};
|
package/src/utils/attributes.js
CHANGED
@@ -13,17 +13,19 @@ export const linkControlAttribute = {
|
|
13
13
|
},
|
14
14
|
};
|
15
15
|
|
16
|
-
export const
|
17
|
-
|
16
|
+
export const getMediaAttribute = (name = 'media') => ({
|
17
|
+
[`${name}`]: {
|
18
18
|
type: 'object',
|
19
19
|
default: {
|
20
20
|
id: null,
|
21
|
-
url:
|
22
|
-
alt:
|
23
|
-
|
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
|
40
|
-
|
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
|
-
*
|
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
|
-
* @
|
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
|
-
|
150
|
-
|
151
|
-
|
152
|
-
hasIncludeOverlayAttribute = false,
|
140
|
+
hasBackgroundMedia = false,
|
141
|
+
mediaAttributeName = 'media',
|
142
|
+
hasOverlay = false,
|
153
143
|
} = {}) => {
|
154
|
-
|
155
|
-
|
156
|
-
isIncludeOverlay: {
|
144
|
+
const backgroundMediaAttribute = {
|
145
|
+
isIncludeBackgroundMedia: {
|
157
146
|
type: 'boolean',
|
158
|
-
default:
|
159
|
-
}
|
147
|
+
default: null,
|
148
|
+
},
|
149
|
+
backgroundMediaType: {
|
150
|
+
type: 'string',
|
151
|
+
default: null,
|
152
|
+
},
|
153
|
+
...getMediaAttribute(mediaAttributeName),
|
160
154
|
};
|
161
155
|
|
162
|
-
const
|
163
|
-
|
156
|
+
const overlayAttribute = {
|
157
|
+
isIncludeOverlay: {
|
164
158
|
type: 'boolean',
|
165
|
-
default:
|
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:
|
170
|
+
default: null,
|
179
171
|
},
|
180
172
|
|
181
|
-
...
|
173
|
+
...(hasBackgroundMedia ? backgroundMediaAttribute : {}),
|
182
174
|
|
183
|
-
...(
|
175
|
+
...(hasOverlay ? overlayAttribute : {}),
|
184
176
|
};
|
185
177
|
};
|
186
178
|
|