@secretstache/wordpress-gutenberg 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- 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/index.d.ts +152 -0
- package/src/utils/constants.js +0 -6
- package/src/utils/helpers.js +20 -1
package/package.json
CHANGED
package/src/index.d.ts
ADDED
@@ -0,0 +1,152 @@
|
|
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
|
+
}
|
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
|
}
|