@secretstache/wordpress-gutenberg 0.5.1 → 0.5.3
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/README.md +13 -3
- package/build/index.js +3 -3
- package/build/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/ColorPaletteControl.js +24 -3
- package/src/hooks/useColorChange.js +7 -0
- package/src/hooks/useThemeColors.js +1 -1
- package/src/utils/constants.js +0 -6
- package/src/utils/helpers.js +20 -1
package/package.json
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { BaseControl, ColorPalette } from '@wordpress/components';
|
2
|
-
import { useThemeColors
|
2
|
+
import { useThemeColors } from '../hooks/index.js';
|
3
3
|
|
4
4
|
export const ColorPaletteControl = ({
|
5
5
|
label = 'Color',
|
@@ -7,9 +7,29 @@ export const ColorPaletteControl = ({
|
|
7
7
|
attributeName,
|
8
8
|
setAttributes,
|
9
9
|
allowedColors,
|
10
|
+
...other
|
10
11
|
}) => {
|
11
12
|
const colors = useThemeColors(allowedColors);
|
12
|
-
|
13
|
+
|
14
|
+
const onChange = (colorValue) => {
|
15
|
+
const selectedColor = colors.find(color => color.color === colorValue);
|
16
|
+
|
17
|
+
if (colorValue) {
|
18
|
+
setAttributes({
|
19
|
+
[attributeName]: {
|
20
|
+
value: colorValue,
|
21
|
+
slug: selectedColor?.slug || '',
|
22
|
+
}
|
23
|
+
})
|
24
|
+
} else {
|
25
|
+
setAttributes({
|
26
|
+
[attributeName]: {
|
27
|
+
value: '',
|
28
|
+
slug: '',
|
29
|
+
}
|
30
|
+
})
|
31
|
+
}
|
32
|
+
};
|
13
33
|
|
14
34
|
return (
|
15
35
|
<BaseControl label={label}>
|
@@ -17,7 +37,8 @@ export const ColorPaletteControl = ({
|
|
17
37
|
colors={colors}
|
18
38
|
value={value}
|
19
39
|
disableCustomColors={true}
|
20
|
-
onChange={
|
40
|
+
onChange={onChange}
|
41
|
+
{...other}
|
21
42
|
/>
|
22
43
|
</BaseControl>
|
23
44
|
);
|
@@ -1,4 +1,11 @@
|
|
1
|
+
import { deprecationWarning } from '../utils/internal/helpers.js';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* @deprecated since 0.5.3
|
5
|
+
*/
|
1
6
|
export const useColorChange = (colors, setAttributes) => (colorValue, property) => {
|
7
|
+
deprecationWarning('Warning: useColorChange is deprecated since version 0.5.3 and will be removed in future versions.');
|
8
|
+
|
2
9
|
const selectedColor = colors.find(color => color.color === colorValue);
|
3
10
|
|
4
11
|
setAttributes({
|
package/src/utils/constants.js
CHANGED
package/src/utils/helpers.js
CHANGED
@@ -3,7 +3,7 @@ import apiFetch from '@wordpress/api-fetch';
|
|
3
3
|
import slugify from 'slugify';
|
4
4
|
import classNames from 'classnames';
|
5
5
|
import { select, subscribe } from '@wordpress/data';
|
6
|
-
import { getBlockType, unregisterBlockType } from '@wordpress/blocks';
|
6
|
+
import { getBlockType, registerBlockType, unregisterBlockType } from '@wordpress/blocks';
|
7
7
|
|
8
8
|
/**
|
9
9
|
* Loads select options by fetching posts from WordPress REST API.
|
@@ -234,4 +234,23 @@ const unsetBlockForPostType = (blockName, postType) => {
|
|
234
234
|
},
|
235
235
|
'core/editor'
|
236
236
|
);
|
237
|
+
};
|
238
|
+
|
239
|
+
/**
|
240
|
+
* Update the API version of a specific block.
|
241
|
+
*
|
242
|
+
* @param {string} blockName - The name of the block to update (e.g., 'gravityforms/form').
|
243
|
+
* @param {number} [apiVersion=3] - The API version to set for the block. Defaults to 3.
|
244
|
+
*/
|
245
|
+
export function updateBlockApiVersion(blockName, apiVersion = 3) {
|
246
|
+
const blockSettings = getBlockType(blockName);
|
247
|
+
|
248
|
+
if (blockSettings) {
|
249
|
+
unregisterBlockType(blockName);
|
250
|
+
|
251
|
+
registerBlockType(blockName, {
|
252
|
+
...blockSettings,
|
253
|
+
apiVersion,
|
254
|
+
});
|
255
|
+
}
|
237
256
|
}
|