@secretstache/wordpress-gutenberg 0.5.2 → 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.2",
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
 
package/src/index.d.ts DELETED
@@ -1,152 +0,0 @@
1
- declare module '@secretstache/wordpress-gutenberg' {
2
- import { ReactNode, FC } from 'react';
3
- import { BlockInstance } from '@wordpress/blocks';
4
-
5
- // Constants
6
- export const MEDIA_TYPE: {
7
- IMAGE: 'image';
8
- VIDEO: 'video';
9
- ANIMATION: 'animation';
10
- };
11
-
12
- // Components
13
- export interface ColorPaletteControlProps {
14
- label?: string;
15
- value: string;
16
- attributeName: string;
17
- setAttributes: (attrs: any) => void;
18
- allowedColors?: string[];
19
- }
20
- export const ColorPaletteControl: FC<ColorPaletteControlProps>;
21
-
22
- export interface MediaControlProps {
23
- mediaId: number;
24
- mediaUrl: string;
25
- mediaFileName?: string;
26
- onSelect: (media: any) => void;
27
- onRemove: () => void;
28
- type?: 'image' | 'video' | 'animation';
29
- selectButtonLabel?: string;
30
- removeButtonLabel?: string;
31
- }
32
- export const MediaControl: FC<MediaControlProps>;
33
-
34
- export interface PreviewControlProps {
35
- checked: boolean;
36
- onChange: (value: boolean) => void;
37
- help?: string;
38
- label?: string;
39
- }
40
- export const PreviewControl: FC<PreviewControlProps>;
41
-
42
- export interface ResourcesWrapperProps {
43
- isLoading?: boolean;
44
- isEmptyResources?: boolean;
45
- isEmptySelection?: boolean;
46
- isPlaceholder?: boolean;
47
- emptyResourcesMessage?: string;
48
- emptySelectionMessage?: string;
49
- placeholderProps?: {
50
- icon?: string;
51
- instructions?: string;
52
- [key: string]: any;
53
- };
54
- children?: ReactNode;
55
- }
56
- export const ResourcesWrapper: FC<ResourcesWrapperProps>;
57
-
58
- export interface DataQueryControlsProps {
59
- dataSourceLabel?: string;
60
- dataSource: string;
61
- onDataSourceChange: (value: string) => void;
62
- queryTypeLabel?: string;
63
- queryType: string;
64
- onQueryTypeChange: (value: string) => void;
65
- settings: Array<{
66
- value: string;
67
- label: string;
68
- queries?: Array<{
69
- value: string;
70
- label: string;
71
- }>;
72
- }>;
73
- }
74
- export const DataQueryControls: FC<DataQueryControlsProps>;
75
-
76
- // Hooks
77
- export function usePreviewControl(): {
78
- isPreview: boolean;
79
- setIsPreview: (value: boolean) => void;
80
- PreviewControl: FC<PreviewControlProps>;
81
- };
82
-
83
- export function useThemeColors(allowedColors?: string[]): Array<{
84
- name: string;
85
- slug: string;
86
- color: string;
87
- }>;
88
-
89
- export function useColorChange(
90
- colors: Array<{ color: string; slug: string }>,
91
- setAttributes: (attrs: any) => void
92
- ): (colorValue: string, property: string) => void;
93
-
94
- export function useDataQuery(config: {
95
- postType: string | (() => string);
96
- curatedPostsIds?: number[];
97
- taxonomySlug?: string;
98
- curatedTermsIds?: number[];
99
- numberOfPosts?: number;
100
- extraQueryArgs?: Record<string, any>;
101
- }, dependencies?: any[]): {
102
- postsToShow: any[];
103
- isResolving: boolean;
104
- isEmpty: boolean;
105
- };
106
-
107
- export function useParentBlock(
108
- parentBlockName: string,
109
- blockClientIdToLimitSearch?: string
110
- ): BlockInstance | null;
111
-
112
- export function useSlider(
113
- isEnabled: boolean,
114
- setupSlider: (element: HTMLElement) => any,
115
- cleanCallback?: () => void,
116
- dependencies?: any[]
117
- ): {
118
- sliderElRef: React.RefObject<HTMLElement>;
119
- sliderInstance: React.RefObject<any>;
120
- };
121
-
122
- export function useAccordionItem(
123
- itemId: string,
124
- activeItemId: string | null,
125
- setActiveItemId: (id: string | null) => void,
126
- contentSelector: string,
127
- heightObserverDeps?: any[]
128
- ): {
129
- blockRef: React.RefObject<HTMLElement>;
130
- toggleItem: () => void;
131
- openContent: () => void;
132
- closeContent: () => void;
133
- isActive: boolean;
134
- };
135
-
136
- export function useAllowedBlocks(
137
- blockName: string,
138
- excludedBlocks?: string[]
139
- ): string[];
140
-
141
- export function useChildBlockPosition(
142
- childClientId: string
143
- ): {
144
- block: BlockInstance | null;
145
- parentBlock: BlockInstance | null;
146
- position: number;
147
- };
148
-
149
- export function useFilterBlocks(
150
- filter: (block: BlockInstance) => boolean
151
- ): string[];
152
- }