@secretstache/wordpress-gutenberg 0.5.11 → 0.5.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@secretstache/wordpress-gutenberg",
3
- "version": "0.5.11",
3
+ "version": "0.5.13",
4
4
  "description": "",
5
5
  "author": "Secret Stache",
6
6
  "license": "GPL-2.0-or-later",
@@ -1,14 +1,17 @@
1
1
  import { InnerBlocks } from '@wordpress/block-editor';
2
+ import classNames from 'classnames';
2
3
 
3
4
  export const EmptyBlockAppender = (props) => {
4
5
  const {
5
6
  showIcon = true,
7
+ showAppender = true,
6
8
  title = 'This block is empty',
7
9
  text = 'Use the "+" button below to add content blocks',
10
+ className,
8
11
  } = props;
9
12
 
10
13
  return (
11
- <div className="empty-block-appender">
14
+ <div className={classNames('empty-block-appender', className)}>
12
15
  <div className="empty-block-appender__content">
13
16
  {
14
17
  showIcon && (
@@ -22,9 +25,13 @@ export const EmptyBlockAppender = (props) => {
22
25
  <p className="empty-block-appender__text">{text}</p>
23
26
  </div>
24
27
 
25
- <div className="empty-block-appender__button">
26
- <InnerBlocks.ButtonBlockAppender />
27
- </div>
28
+ {
29
+ showAppender && (
30
+ <div className="empty-block-appender__button">
31
+ <InnerBlocks.ButtonBlockAppender />
32
+ </div>
33
+ )
34
+ }
28
35
  </div>
29
36
  );
30
37
  };
@@ -20,8 +20,7 @@ export const useParentBlock = (
20
20
  return null;
21
21
  }
22
22
 
23
- // Return the selected block if it already matches the target type
24
- if (currentBlock?.name === parentBlockName) {
23
+ if (currentBlock.clientId === blockClientIdToLimitSearch && currentBlock.name === parentBlockName) {
25
24
  return currentBlock;
26
25
  }
27
26
 
@@ -1,4 +1,4 @@
1
- import { useSelect, useDispatch } from '@wordpress/data';
1
+ import { useSelect, useDispatch, select } from '@wordpress/data';
2
2
  import { store as blockEditorStore } from '@wordpress/block-editor';
3
3
  import { useLayoutEffect, useState } from '@wordpress/element';
4
4
  import { Button } from '@wordpress/components';
@@ -50,12 +50,40 @@ export const useTabs = (tabsClientId, tabItemName) => {
50
50
 
51
51
  const parentBlock = useParentBlock(tabItemName, tabsClientId);
52
52
 
53
+ /**
54
+ * Sets the active tab when focus/selection is inside any inner block of a tab item.
55
+ * For example, if the user selects text inside a tab, that tab should become active.
56
+ */
53
57
  useLayoutEffect(() => {
54
58
  if (parentBlock) {
55
59
  setActiveItemId(parentBlock.clientId);
56
60
  }
57
61
  }, [ parentBlock ]);
58
62
 
63
+ /**
64
+ * Sets the active tab when the tab-item block itself is selected in the editor sidebar.
65
+ * Ensures the selected tab-item belongs directly to this Tabs block (avoids conflicts if there are multiple Tabs on the page).
66
+ */
67
+ useLayoutEffect(() => {
68
+ // Early return if there is no selected block, or if the selected block is not a tab-item.
69
+ const isTabItemBlockSelected = selectedBlock && selectedBlock.name === tabItemName;
70
+
71
+ if (!isTabItemBlockSelected) {
72
+ return;
73
+ }
74
+
75
+ // Get the parent block clientId for this selected tab-item block.
76
+ const selectedTabItemBlock = selectedBlock;
77
+ const tabItemParentId = select('core/block-editor').getBlockRootClientId(selectedTabItemBlock.clientId);
78
+
79
+ // Only activate the tab if it is a direct child of this Tabs instance.
80
+ const isDirectChildOfCurrentTabs = tabItemParentId === tabsClientId;
81
+
82
+ if (isDirectChildOfCurrentTabs) {
83
+ setActiveItemId(selectedTabItemBlock.clientId);
84
+ }
85
+ }, [ selectedBlock, tabItemName, tabsClientId ]);
86
+
59
87
  const createTab = (blockName, attributes = {}, position = tabsCount) => {
60
88
  const newTab = createBlock(blockName, attributes);
61
89
  insertBlock(newTab, position, tabsClientId);