This repository has been archived by the owner on Oct 16, 2023. It is now read-only.
-
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.
Refactor: form builder to use wp-scripts (#180)
* refactor: update component imports, use wp-scripts * feature: add custom categories * chore: add ts-ignores to fix build * chore: udpate since tags * refactor: label section category as layout * feature: add default block cats --------- Co-authored-by: Jon Waldstein <jonwaldstein@jons-air.mynetworksettings.com>
- Loading branch information
1 parent
d26067b
commit 25b01ee
Showing
21 changed files
with
865 additions
and
314 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
3 changes: 1 addition & 2 deletions
3
packages/form-builder/src/blocks/fields/amount/inspector/add-button.tsx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import {Button} from '@wordpress/components'; | ||
import {chevronLeft, chevronRight} from '@wordpress/icons'; | ||
import {__, isRTL} from '@wordpress/i18n'; | ||
import {useDispatch, useSelect} from '@wordpress/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import BlockIcon from './BlockIcon'; | ||
import {store as blockEditorStore} from '@wordpress/block-editor'; | ||
|
||
function BlockCard({title, icon, description, className = ''}) { | ||
// @ts-ignore | ||
const isOffCanvasNavigationEditorEnabled = window?.__experimentalEnableOffCanvasNavigationEditor === true; | ||
|
||
const {parentNavBlockClientId} = useSelect((select) => { | ||
// @ts-ignore | ||
const {getSelectedBlockClientId, getBlockParentsByBlockName} = select(blockEditorStore); | ||
|
||
const _selectedBlockClientId = getSelectedBlockClientId(); | ||
|
||
return { | ||
parentNavBlockClientId: getBlockParentsByBlockName(_selectedBlockClientId, 'core/navigation', true)[0], | ||
}; | ||
}, []); | ||
|
||
const {selectBlock} = useDispatch(blockEditorStore); | ||
|
||
return ( | ||
<div className={classnames('block-editor-block-card', className)}> | ||
{isOffCanvasNavigationEditorEnabled && parentNavBlockClientId && ( | ||
<Button | ||
onClick={() => selectBlock(parentNavBlockClientId)} | ||
label={__('Go to parent Navigation block')} | ||
style={ | ||
// TODO: This style override is also used in ToolsPanelHeader. | ||
// It should be supported out-of-the-box by Button. | ||
{minWidth: 24, padding: 0} | ||
} | ||
icon={isRTL() ? chevronRight : chevronLeft} | ||
isSmall | ||
/> | ||
)} | ||
{/*@ts-ignore*/} | ||
<BlockIcon icon={icon} showColors /> | ||
<div className="block-editor-block-card__content"> | ||
<h2 className="block-editor-block-card__title">{title}</h2> | ||
<span className="block-editor-block-card__description">{description}</span> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default BlockCard; |
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,44 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import {Icon} from '@wordpress/components'; | ||
import {blockDefault} from '@wordpress/icons'; | ||
import {memo} from '@wordpress/element'; | ||
|
||
function BlockIcon({icon, showColors = false, className, context}) { | ||
if (icon?.src === 'block-default') { | ||
icon = { | ||
src: blockDefault, | ||
}; | ||
} | ||
|
||
// @ts-ignore | ||
const renderedIcon = <Icon icon={icon && icon.src ? icon.src : icon} context={context} />; | ||
const style = showColors | ||
? { | ||
backgroundColor: icon && icon.background, | ||
color: icon && icon.foreground, | ||
} | ||
: {}; | ||
|
||
return ( | ||
<span | ||
style={style} | ||
className={classnames('block-editor-block-icon', className, { | ||
'has-colors': showColors, | ||
})} | ||
> | ||
{renderedIcon} | ||
</span> | ||
); | ||
} | ||
|
||
/** | ||
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/block-icon/README.md | ||
*/ | ||
export default memo( BlockIcon ); |
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
2 changes: 1 addition & 1 deletion
2
packages/form-builder/src/components/sidebar/panels/FieldTypesList.tsx
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,15 @@ | ||
import {useSelect} from "@wordpress/data"; | ||
import {store as blockEditorStore} from "@wordpress/block-editor/build/store"; | ||
import {useSelect} from '@wordpress/data'; | ||
import {store as blockEditorStore} from '@wordpress/block-editor'; | ||
|
||
const useSelectedBlocks = () => { | ||
const { | ||
selectedBlocks, | ||
} = useSelect(select => { | ||
const { | ||
getSelectedBlockClientIds, | ||
} = select(blockEditorStore); | ||
const {selectedBlocks} = useSelect((select) => { | ||
const {getSelectedBlockClientIds} = select(blockEditorStore); | ||
return { | ||
selectedBlocks: getSelectedBlockClientIds(), | ||
}; | ||
}); | ||
|
||
return selectedBlocks | ||
return selectedBlocks; | ||
}; | ||
|
||
export default useSelectedBlocks; |
Oops, something went wrong.