@secretstache/wordpress-gutenberg 0.3.8 → 0.3.10

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.3.8",
3
+ "version": "0.3.10",
4
4
  "description": "",
5
5
  "author": "Secret Stache",
6
6
  "license": "GPL-2.0-or-later",
@@ -1,6 +1,8 @@
1
1
  import { RadioControl } from '@wordpress/components';
2
2
 
3
- // TODO: add support of curated posts, categories; consider merging with the useDataQuery hook
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
+ };
@@ -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'
@@ -1,4 +1,4 @@
1
- export { usePreviewToggle } from './usePreviewToggle.js';
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';
@@ -1,6 +1,7 @@
1
1
  import { useSelect } from '@wordpress/data';
2
2
  import { QUERY_TYPES } from '../utils';
3
3
 
4
+ // TODO: numberOfPosts -1 is not a valid value, the API requires the per_page to be >= 1
4
5
  export const useDataQuery = (props) => {
5
6
  const {
6
7
  getPostType,
@@ -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
+ };
@@ -15,7 +15,7 @@ export const useSlider = ({ isEnabled, setupSlider, dependencies = [] }) => {
15
15
  sliderInstance.current = null;
16
16
  }
17
17
  };
18
- }, [isEnabled, ...dependencies]);
18
+ }, [ isEnabled, ...dependencies ]);
19
19
 
20
20
  return {
21
21
  sliderElRef,
@@ -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',
@@ -8,9 +8,10 @@ export const hideRootBlockForOtherBlocks = (rootBlockName) => {
8
8
  'ssm/with-root-block',
9
9
  (blockSettings, blockName) => {
10
10
  const isRootBlock = blockName === rootBlockName;
11
- const hasOwnAllowedBlocks = blockSettings?.allowedBlocks;
11
+ const hasOwnAllowedBlocks = !!blockSettings?.allowedBlocks;
12
+ const hasParent = !!blockSettings?.parent;
12
13
 
13
- if (isRootBlock || hasOwnAllowedBlocks) {
14
+ if (isRootBlock || hasParent || hasOwnAllowedBlocks) {
14
15
  return blockSettings;
15
16
  }
16
17
 
@@ -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
- };