-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
419 additions
and
0 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
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,10 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 2, | ||
"name": "core/form", | ||
"title": "Form", | ||
"category": "common", | ||
"description": "A form.", | ||
"keywords": [ "container", "wrapper", "row", "section" ], | ||
"textdomain": "default" | ||
} |
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,14 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { InnerBlocks, useBlockProps } from '@wordpress/block-editor'; | ||
|
||
const Edit = () => { | ||
const blockProps = useBlockProps(); | ||
return ( | ||
<form { ...blockProps }> | ||
<InnerBlocks /> | ||
</form> | ||
); | ||
}; | ||
export default Edit; |
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,137 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { View } from 'react-native'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { withSelect } from '@wordpress/data'; | ||
import { | ||
compose, | ||
withPreferredColorScheme, | ||
useResizeObserver, | ||
} from '@wordpress/compose'; | ||
import { | ||
InnerBlocks, | ||
store as blockEditorStore, | ||
} from '@wordpress/block-editor'; | ||
import { useCallback } from '@wordpress/element'; | ||
import { alignmentHelpers } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import styles from './editor.scss'; | ||
|
||
const { isFullWidth } = alignmentHelpers; | ||
|
||
function GroupEdit( { | ||
attributes, | ||
hasInnerBlocks, | ||
isSelected, | ||
isLastInnerBlockSelected, | ||
getStylesFromColorScheme, | ||
style, | ||
blockWidth, | ||
} ) { | ||
const { align } = attributes; | ||
const [ resizeObserver, sizes ] = useResizeObserver(); | ||
const { width } = sizes || { width: 0 }; | ||
|
||
const renderAppender = useCallback( | ||
() => ( | ||
<View | ||
style={ [ | ||
! hasInnerBlocks && styles.groupAppender, | ||
isFullWidth( align ) && | ||
! hasInnerBlocks && | ||
styles.fullwidthGroupAppender, | ||
isFullWidth( align ) && | ||
hasInnerBlocks && | ||
styles.fullwidthHasInnerGroupAppender, | ||
] } | ||
> | ||
<InnerBlocks.ButtonBlockAppender /> | ||
</View> | ||
), | ||
[ align, hasInnerBlocks ] | ||
); | ||
|
||
if ( ! isSelected && ! hasInnerBlocks ) { | ||
return ( | ||
<View | ||
style={ [ | ||
getStylesFromColorScheme( | ||
styles.groupPlaceholder, | ||
styles.groupPlaceholderDark | ||
), | ||
! hasInnerBlocks && { | ||
...styles.marginVerticalDense, | ||
...styles.marginHorizontalNone, | ||
}, | ||
] } | ||
/> | ||
); | ||
} | ||
|
||
return ( | ||
<View | ||
style={ [ | ||
isSelected && hasInnerBlocks && styles.innerBlocks, | ||
style, | ||
isSelected && | ||
hasInnerBlocks && | ||
style?.backgroundColor && | ||
styles.hasBackgroundAppender, | ||
isLastInnerBlockSelected && | ||
style?.backgroundColor && | ||
styles.isLastInnerBlockSelected, | ||
] } | ||
> | ||
{ resizeObserver } | ||
<InnerBlocks | ||
renderAppender={ isSelected && renderAppender } | ||
parentWidth={ width } | ||
blockWidth={ blockWidth } | ||
/> | ||
</View> | ||
); | ||
} | ||
|
||
export default compose( [ | ||
withSelect( ( select, { clientId } ) => { | ||
const { | ||
getBlock, | ||
getBlockIndex, | ||
hasSelectedInnerBlock, | ||
getBlockRootClientId, | ||
getSelectedBlockClientId, | ||
getBlockAttributes, | ||
} = select( blockEditorStore ); | ||
|
||
const block = getBlock( clientId ); | ||
const hasInnerBlocks = !! ( block && block.innerBlocks.length ); | ||
const isInnerBlockSelected = | ||
hasInnerBlocks && hasSelectedInnerBlock( clientId, true ); | ||
let isLastInnerBlockSelected = false; | ||
|
||
if ( isInnerBlockSelected ) { | ||
const { innerBlocks } = block; | ||
const selectedBlockClientId = getSelectedBlockClientId(); | ||
const totalInnerBlocks = innerBlocks.length - 1; | ||
const blockIndex = getBlockIndex( selectedBlockClientId ); | ||
isLastInnerBlockSelected = totalInnerBlocks === blockIndex; | ||
} | ||
|
||
const parentId = getBlockRootClientId( clientId ); | ||
const parentBlockAlignment = getBlockAttributes( parentId )?.align; | ||
|
||
return { | ||
hasInnerBlocks, | ||
isLastInnerBlockSelected, | ||
parentBlockAlignment, | ||
}; | ||
} ), | ||
withPreferredColorScheme, | ||
] )( GroupEdit ); |
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 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import initBlock from '../utils/init-block'; | ||
import edit from './edit'; | ||
import metadata from './block.json'; | ||
import save from './save'; | ||
|
||
const { name } = metadata; | ||
|
||
export { metadata, name }; | ||
|
||
export const settings = { | ||
edit, | ||
save, | ||
}; | ||
|
||
export const init = () => initBlock( { name, metadata, settings } ); |
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 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { init } from './'; | ||
|
||
export default init(); |
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,14 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { InnerBlocks, useBlockProps } from '@wordpress/block-editor'; | ||
|
||
const Save = () => { | ||
const blockProps = useBlockProps.save(); | ||
return ( | ||
<form { ...blockProps }> | ||
<InnerBlocks.Content /> | ||
</form> | ||
); | ||
}; | ||
export default Save; |
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,26 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 2, | ||
"name": "core/input-field", | ||
"title": "Input field", | ||
"category": "common", | ||
"parent": [ "core/form" ], | ||
"description": "The basic building block for forms.", | ||
"keywords": [ "input", "text", "textarea" ], | ||
"textdomain": "default", | ||
"attributes": { | ||
"type": { | ||
"type": "string", | ||
"default": "text" | ||
}, | ||
"label": { | ||
"type": "string", | ||
"default": "Label" | ||
}, | ||
"inlineLabel": { | ||
"type": "boolean", | ||
"default": false | ||
} | ||
}, | ||
"style": [ "wp-block-input-field" ] | ||
} |
Oops, something went wrong.