@secretstache/wordpress-gutenberg 0.5.1 → 0.5.3

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.5.1",
3
+ "version": "0.5.3",
4
4
  "description": "",
5
5
  "author": "Secret Stache",
6
6
  "license": "GPL-2.0-or-later",
@@ -1,5 +1,5 @@
1
1
  import { BaseControl, ColorPalette } from '@wordpress/components';
2
- import { useThemeColors, useColorChange } from '../hooks/index.js';
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
- const onColorChange = useColorChange(colors, setAttributes);
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={(colorValue) => onColorChange(colorValue, attributeName)}
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({
@@ -14,6 +14,6 @@ export const useThemeColors = (allowedColors = []) => {
14
14
  }
15
15
 
16
16
  return allColors;
17
- }, [allowedColors]);
17
+ }, [ allowedColors ]);
18
18
  };
19
19
 
@@ -1,9 +1,3 @@
1
- export const QUERY_TYPE = {
2
- LATEST: 'latest',
3
- CURATED: 'curated',
4
- BY_CATEGORY: 'by_category'
5
- };
6
-
7
1
  export const MEDIA_TYPE = {
8
2
  IMAGE: 'image',
9
3
  VIDEO: 'video',
@@ -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
  }