@secretstache/wordpress-gutenberg 0.5.2 → 0.5.4
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/build/index.js +3 -3
- package/build/index.js.map +1 -1
- package/build/styles.css +2 -0
- package/package.json +1 -1
- package/src/components/ColorPaletteControl.js +24 -3
- package/src/components/MediaControl.js +65 -58
- package/src/hooks/useColorChange.js +7 -0
- package/src/hooks/useThemeColors.js +1 -1
- package/src/styles/_link-control.scss +4 -0
- package/src/index.d.ts +0 -152
package/build/styles.css
CHANGED
@@ -153,6 +153,8 @@
|
|
153
153
|
.editor-sidebar .block-editor-link-control {
|
154
154
|
min-width: 100%;
|
155
155
|
width: 100%; }
|
156
|
+
.editor-sidebar .block-editor-link-control .block-editor-url-input {
|
157
|
+
min-width: 100%; }
|
156
158
|
.editor-sidebar .block-editor-link-control .block-editor-url-input__input {
|
157
159
|
width: 100%; }
|
158
160
|
.editor-sidebar .block-editor-link-control .components-base-control {
|
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,4 @@
|
|
1
|
-
import { Button, Icon as WPIcon } from '@wordpress/components';
|
1
|
+
import { BaseControl, Button, Icon as WPIcon } from '@wordpress/components';
|
2
2
|
import { MediaUpload, MediaUploadCheck } from '@wordpress/block-editor';
|
3
3
|
import { page as pageIcon } from '@wordpress/icons';
|
4
4
|
|
@@ -110,6 +110,7 @@ export const AnimationRenderer = ({
|
|
110
110
|
};
|
111
111
|
|
112
112
|
export const MediaControl = ({
|
113
|
+
label,
|
113
114
|
mediaId,
|
114
115
|
mediaUrl,
|
115
116
|
mediaFileName = '',
|
@@ -122,69 +123,75 @@ export const MediaControl = ({
|
|
122
123
|
}) => {
|
123
124
|
if (type === MEDIA_TYPE.IMAGE) {
|
124
125
|
return (
|
125
|
-
<
|
126
|
-
<
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
126
|
+
<BaseControl label={label || 'Image'}>
|
127
|
+
<MediaUploadCheck>
|
128
|
+
<MediaUpload
|
129
|
+
onSelect={onSelect}
|
130
|
+
allowedTypes={['image', 'image/svg+xml']}
|
131
|
+
accept="image/*"
|
132
|
+
value={mediaId}
|
133
|
+
render={({ open }) => (
|
134
|
+
<ImageRenderer
|
135
|
+
imageId={mediaId}
|
136
|
+
imageUrl={mediaUrl}
|
137
|
+
onImageClick={open}
|
138
|
+
onSelectClick={open}
|
139
|
+
onRemoveClick={onRemove}
|
140
|
+
selectButtonLabel={selectButtonLabel || 'Select Image'}
|
141
|
+
removeButtonLabel={removeButtonLabel || 'Remove Image'}
|
142
|
+
/>
|
143
|
+
)}
|
144
|
+
{...other}
|
145
|
+
/>
|
146
|
+
</MediaUploadCheck>
|
147
|
+
</BaseControl>
|
145
148
|
);
|
146
149
|
} else if (type === MEDIA_TYPE.VIDEO) {
|
147
150
|
return (
|
148
|
-
<
|
149
|
-
<
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
151
|
+
<BaseControl label={label || 'Video'}>
|
152
|
+
<MediaUploadCheck>
|
153
|
+
<MediaUpload
|
154
|
+
onSelect={onSelect}
|
155
|
+
allowedTypes={['video']}
|
156
|
+
value={mediaId}
|
157
|
+
render={({ open }) => (
|
158
|
+
<VideoRenderer
|
159
|
+
videoId={mediaId}
|
160
|
+
videoUrl={mediaUrl}
|
161
|
+
onSelectClick={open}
|
162
|
+
onRemoveClick={onRemove}
|
163
|
+
selectButtonLabel={selectButtonLabel || 'Select Video'}
|
164
|
+
removeButtonLabel={removeButtonLabel || 'Remove Video'}
|
165
|
+
/>
|
166
|
+
)}
|
167
|
+
{...other}
|
168
|
+
/>
|
169
|
+
</MediaUploadCheck>
|
170
|
+
</BaseControl>
|
166
171
|
);
|
167
172
|
} else if (type === MEDIA_TYPE.ANIMATION) {
|
168
173
|
return (
|
169
|
-
<
|
170
|
-
<
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
174
|
+
<BaseControl label={label || 'Animation'}>
|
175
|
+
<MediaUploadCheck>
|
176
|
+
<MediaUpload
|
177
|
+
onSelect={onSelect}
|
178
|
+
allowedTypes={['application/json', 'text/plain', 'application/lottie']}
|
179
|
+
value={mediaId}
|
180
|
+
render={({ open }) => (
|
181
|
+
<AnimationRenderer
|
182
|
+
animationFileId={mediaId}
|
183
|
+
animationFileUrl={mediaUrl}
|
184
|
+
animationFileName={mediaFileName}
|
185
|
+
onSelectClick={open}
|
186
|
+
onRemoveClick={onRemove}
|
187
|
+
selectButtonLabel={selectButtonLabel || 'Select Animation'}
|
188
|
+
removeButtonLabel={removeButtonLabel || 'Remove Animation'}
|
189
|
+
/>
|
190
|
+
)}
|
191
|
+
{...other}
|
192
|
+
/>
|
193
|
+
</MediaUploadCheck>
|
194
|
+
</BaseControl>
|
188
195
|
);
|
189
196
|
} else {
|
190
197
|
throw new Error('Unrecognized media type.');
|
@@ -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/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
|
-
}
|