@secretstache/wordpress-gutenberg 0.3.9 → 0.3.10
Sign up to get free protection for your applications and to get access to all the features.
- package/build/index.js +3 -3
- package/build/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/DataQueryControls.js +3 -1
- package/src/components/InsertBlockToolbar.js +36 -0
- package/src/components/index.js +1 -0
- package/src/hooks/index.js +1 -1
- package/src/hooks/useDataQuery.js +1 -0
- package/src/hooks/usePreviewControl.js +31 -0
- package/src/hooks/useSlider.js +1 -1
- package/src/utils/attributes.js +2 -1
- package/src/hooks/usePreviewToggle.js +0 -32
package/package.json
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
import { RadioControl } from '@wordpress/components';
|
2
2
|
|
3
|
-
// TODO: add support of curated posts, categories
|
3
|
+
// TODO: 1. add support of curated posts, categories
|
4
|
+
// TODO: 2. consider merging with the useDataQuery hook
|
5
|
+
// TODO: 3. can't pass disabled prop to RadioControl
|
4
6
|
export const DataQueryControls = (props) => {
|
5
7
|
const {
|
6
8
|
dataSourceLabel = 'Data Source',
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import { BlockControls } from '@wordpress/block-editor';
|
2
|
+
import { select, useDispatch } from '@wordpress/data';
|
3
|
+
import { createBlock } from '@wordpress/blocks';
|
4
|
+
import { useCallback } from '@wordpress/element';
|
5
|
+
import { Toolbar, ToolbarButton } from '@wordpress/components';
|
6
|
+
|
7
|
+
export const InsertBlockToolbar = ({ clientId, blockName, group }) => {
|
8
|
+
const { insertBlock } = useDispatch('core/block-editor');
|
9
|
+
|
10
|
+
const insertBlockBefore = useCallback(() => {
|
11
|
+
const block = createBlock(blockName);
|
12
|
+
insertBlock(block, select('core/block-editor').getBlockIndex(clientId));
|
13
|
+
}, []);
|
14
|
+
|
15
|
+
const insertBlockAfter = useCallback(() => {
|
16
|
+
const block = createBlock(blockName);
|
17
|
+
insertBlock(block, select('core/block-editor').getBlockIndex(clientId) + 1);
|
18
|
+
}, []);
|
19
|
+
|
20
|
+
return (
|
21
|
+
<BlockControls group={group}>
|
22
|
+
<Toolbar>
|
23
|
+
<ToolbarButton
|
24
|
+
icon="insert-before"
|
25
|
+
label="Add before"
|
26
|
+
onClick={insertBlockBefore}
|
27
|
+
/>
|
28
|
+
<ToolbarButton
|
29
|
+
icon="insert-after"
|
30
|
+
label="Add after"
|
31
|
+
onClick={insertBlockAfter}
|
32
|
+
/>
|
33
|
+
</Toolbar>
|
34
|
+
</BlockControls>
|
35
|
+
);
|
36
|
+
};
|
package/src/components/index.js
CHANGED
@@ -10,3 +10,4 @@ export { ResponsiveSpacingControl } from './ResponsiveSpacingControl.js';
|
|
10
10
|
export { ResourcesWrapper } from './ResourcesWrapper.js'
|
11
11
|
export { DividersControl } from './DividersControl.js'
|
12
12
|
export { MediaTypeControl } from './MediaTypeControl.js'
|
13
|
+
export { InsertBlockToolbar } from './InsertBlockToolbar.js'
|
package/src/hooks/index.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
export {
|
1
|
+
export { usePreviewControl } from './usePreviewControl.js';
|
2
2
|
export { useSlider } from './useSlider.js';
|
3
3
|
export { useParentBlock } from './useParentBlock.js';
|
4
4
|
export { useColorChange } from './useColorChange';
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import { useCallback, useMemo, useState } from '@wordpress/element';
|
2
|
+
import { ToggleControl } from '@wordpress/components';
|
3
|
+
|
4
|
+
const defaultLabel = 'Enable Preview';
|
5
|
+
const defaultHelpText = 'Please check this option to see how the block will actually look and behave on the frontend.';
|
6
|
+
|
7
|
+
export const usePreviewControl = () => {
|
8
|
+
const [ isPreview, setIsPreview ] = useState(false);
|
9
|
+
|
10
|
+
const onChange = useCallback(() => {
|
11
|
+
setIsPreview(prev => !prev);
|
12
|
+
}, []);
|
13
|
+
|
14
|
+
const PreviewControl = useMemo(() => {
|
15
|
+
return ({ label = defaultLabel, helpText = defaultHelpText, ...props }) => (
|
16
|
+
<ToggleControl
|
17
|
+
label={label}
|
18
|
+
help={helpText}
|
19
|
+
checked={isPreview}
|
20
|
+
onChange={onChange}
|
21
|
+
{...props}
|
22
|
+
/>
|
23
|
+
);
|
24
|
+
});
|
25
|
+
|
26
|
+
return {
|
27
|
+
isPreview,
|
28
|
+
setIsPreview,
|
29
|
+
PreviewControl,
|
30
|
+
};
|
31
|
+
};
|
package/src/hooks/useSlider.js
CHANGED
package/src/utils/attributes.js
CHANGED
@@ -96,7 +96,7 @@ export const numberOfPostsAttribute = {
|
|
96
96
|
},
|
97
97
|
};
|
98
98
|
|
99
|
-
// TODO: make dataSource optional
|
99
|
+
// TODO: make dataSource optional, rebuild it's not easy to use(need to pass sourcesList and queriesList in complex format)
|
100
100
|
export const getDataQueryAttributes = (
|
101
101
|
sourcesList,
|
102
102
|
queriesList,
|
@@ -151,6 +151,7 @@ export const getBaseBackgroundAttributes = ({
|
|
151
151
|
hasIncludeBackgroundMediaAttribute = false,
|
152
152
|
hasIncludeOverlayAttribute = false,
|
153
153
|
} = {}) => {
|
154
|
+
// TODO: add the overlay color attribute
|
154
155
|
const isIncludeOverlayAttribute = {
|
155
156
|
isIncludeOverlay: {
|
156
157
|
type: 'boolean',
|
@@ -1,32 +0,0 @@
|
|
1
|
-
import { useState } from '@wordpress/element';
|
2
|
-
import { ToggleControl } from '@wordpress/components';
|
3
|
-
|
4
|
-
const defaultLabel = 'Enable Preview';
|
5
|
-
const defaultHelpText = 'Please check this option to see how the block will actually look and behave on the frontend.';
|
6
|
-
|
7
|
-
export const usePreviewToggle = (props = {}) => {
|
8
|
-
const {
|
9
|
-
disabled = false,
|
10
|
-
label = defaultLabel,
|
11
|
-
helpText = defaultHelpText,
|
12
|
-
} = props;
|
13
|
-
|
14
|
-
const [ isPreview, setIsPreview ] = useState(false);
|
15
|
-
|
16
|
-
const onChange = () => setIsPreview(prev => !prev);
|
17
|
-
|
18
|
-
const renderPreviewToggle = () => (
|
19
|
-
<ToggleControl
|
20
|
-
label={label}
|
21
|
-
help={helpText}
|
22
|
-
checked={isPreview}
|
23
|
-
onChange={onChange}
|
24
|
-
disabled={disabled}
|
25
|
-
/>
|
26
|
-
);
|
27
|
-
|
28
|
-
return {
|
29
|
-
isPreview,
|
30
|
-
renderPreviewToggle
|
31
|
-
};
|
32
|
-
};
|