-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/issue-629/allow-custom-post-lookup-f…
…unction
- Loading branch information
Showing
14 changed files
with
110 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@alleyinteractive/block-editor-tools": minor | ||
"alley-scripts-demo-plugin": minor | ||
--- | ||
|
||
Introducing new hooks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,20 @@ | ||
export { default as useCurrentPostId } from './use-current-post-id'; | ||
export { default as useCurrentTheme } from './use-current-theme'; | ||
export { default as useDebounce } from './use-debounce'; | ||
export { default as useHasInnerBlocks } from './use-has-inner-blocks'; | ||
export { default as useInnerBlocksIndex } from './use-inner-block-index'; | ||
export { default as useInnerBlocks } from './use-inner-blocks'; | ||
export { default as useInnerBlocksAttributes } from './use-inner-blocks-attributes'; | ||
export { default as useInnerBlocksCount } from './use-inner-blocks-count'; | ||
export { default as useInnerBlocksIndex } from './use-inner-block-index'; | ||
export { default as useMedia } from './use-media'; | ||
export { default as useOption } from './use-option'; | ||
export { default as useParentBlock } from './use-parent-block'; | ||
export { default as useParentBlockAttributes } from './use-parent-block-attributes'; | ||
export { default as usePost } from './use-post'; | ||
export { default as useCurrentPostId } from './use-current-post-id'; | ||
export { default as usePostById } from './use-post-by-id'; | ||
export { default as usePostMeta } from './use-post-meta'; | ||
export { default as usePostMetaValue } from './use-post-meta-value'; | ||
export { default as usePosts } from './use-posts'; | ||
export { default as usePreviewLink } from './use-preview-link'; | ||
export { default as useTerm } from './use-term'; | ||
export { default as useTerms } from './use-terms'; |
2 changes: 1 addition & 1 deletion
2
packages/block-editor-tools/src/hooks/use-current-post-id/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
packages/block-editor-tools/src/hooks/use-current-theme/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Custom Hooks: useCurrentTheme | ||
|
||
A custom React hook to retrieve the current active theme. | ||
|
||
## Usage | ||
|
||
```jsx | ||
const MyBlock = () => { | ||
const theme = useCurrentTheme(); | ||
|
||
if (theme) { | ||
... | ||
} | ||
}; | ||
``` |
15 changes: 15 additions & 0 deletions
15
packages/block-editor-tools/src/hooks/use-current-theme/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { store } from '@wordpress/core-data'; | ||
import { useSelect } from '@wordpress/data'; | ||
|
||
/** | ||
* Get current theme. | ||
* | ||
* @returns {?string} Returns the current active theme, | ||
* or null if the redux store is not initialized. | ||
*/ | ||
const useCurrentTheme = () => useSelect((select) => { | ||
const editorStore = select(store); | ||
return editorStore ? editorStore.getCurrentTheme()?.stylesheet : null; | ||
}, []); | ||
|
||
export default useCurrentTheme; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
packages/block-editor-tools/src/hooks/use-preview-link/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Custom Hooks: usePreviewLink | ||
|
||
A custom React hook to retrieve a post preview link. | ||
|
||
## Usage | ||
|
||
```jsx | ||
const MyBlock = () => { | ||
const previewLink = usePreviewLink(); | ||
}; | ||
``` |
11 changes: 11 additions & 0 deletions
11
packages/block-editor-tools/src/hooks/use-preview-link/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { store } from '@wordpress/core-data'; | ||
import { useSelect } from '@wordpress/data'; | ||
|
||
/** | ||
* Get preview link. | ||
* | ||
* @returns string | ||
*/ | ||
const usePreviewLink = () => useSelect((select) => select(store).getEditedPostPreviewLink(), []); | ||
|
||
export default usePreviewLink; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Custom Hooks: useTerm | ||
|
||
A custom React hook to retrieve term data given a term ID and taxonomy. | ||
|
||
## Usage | ||
|
||
```jsx | ||
const MyBlock = ({ | ||
termId, | ||
taxonomy | ||
}) => { | ||
const termObject = useTerm(termId, taxonomy); | ||
|
||
if (termObject) { | ||
... | ||
} | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { store } from '@wordpress/core-data'; | ||
import { useSelect } from '@wordpress/data'; | ||
|
||
/** | ||
* Gets term data for a specific term given its ID and taxonomy. | ||
* | ||
* @param {int} termId The ID for the term to return. | ||
* @param {string} taxonomy Optional. The taxonomy name. Defaults to 'category'. | ||
* @param {object} options Optional object containing parameters to pass to getEntityRecord. | ||
* @returns {object} An object containing a hasResolved property | ||
* and the returned term object. | ||
*/ | ||
const useTerm = (termId, taxonomy = 'category', options = { context: 'view' }) => useSelect( | ||
(select) => select(store).getEntityRecord('taxonomy', taxonomy, termId, options), | ||
[termId, taxonomy], | ||
); | ||
|
||
export default useTerm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters